• 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 "session/capture_session.h"
17 #include "camera_util.h"
18 #include "hcapture_session_callback_stub.h"
19 #include "input/camera_input.h"
20 #include "camera_log.h"
21 #include "output/photo_output.h"
22 #include "output/preview_output.h"
23 #include "output/video_output.h"
24 
25 namespace OHOS {
26 namespace CameraStandard {
27 namespace {
28     constexpr int32_t DEFAULT_ITEMS = 10;
29     constexpr int32_t DEFAULT_DATA_LENGTH = 100;
30 }
31 
32 const std::unordered_map<camera_focus_state_t, FocusCallback::FocusState> CaptureSession::metaToFwFocusState_ = {
33     {OHOS_CAMERA_FOCUS_STATE_SCAN, FocusCallback::SCAN},
34     {OHOS_CAMERA_FOCUS_STATE_FOCUSED, FocusCallback::FOCUSED},
35     {OHOS_CAMERA_FOCUS_STATE_UNFOCUSED, FocusCallback::UNFOCUSED}
36 };
37 
38 const std::unordered_map<camera_exposure_state_t,
39         ExposureCallback::ExposureState> CaptureSession::metaToFwExposureState_ = {
40     {OHOS_CAMERA_EXPOSURE_STATE_SCAN, ExposureCallback::SCAN},
41     {OHOS_CAMERA_EXPOSURE_STATE_CONVERGED, ExposureCallback::CONVERGED}
42 };
43 
44 const std::unordered_map<camera_exposure_mode_enum_t, ExposureMode> CaptureSession::metaToFwExposureMode_ = {
45     {OHOS_CAMERA_EXPOSURE_MODE_LOCKED, EXPOSURE_MODE_LOCKED},
46     {OHOS_CAMERA_EXPOSURE_MODE_AUTO, EXPOSURE_MODE_AUTO},
47     {OHOS_CAMERA_EXPOSURE_MODE_CONTINUOUS_AUTO, EXPOSURE_MODE_CONTINUOUS_AUTO}
48 };
49 
50 const std::unordered_map<ExposureMode, camera_exposure_mode_enum_t> CaptureSession::fwToMetaExposureMode_ = {
51     {EXPOSURE_MODE_LOCKED, OHOS_CAMERA_EXPOSURE_MODE_LOCKED},
52     {EXPOSURE_MODE_AUTO, OHOS_CAMERA_EXPOSURE_MODE_AUTO},
53     {EXPOSURE_MODE_CONTINUOUS_AUTO, OHOS_CAMERA_EXPOSURE_MODE_CONTINUOUS_AUTO}
54 };
55 
56 const std::unordered_map<camera_focus_mode_enum_t, FocusMode> CaptureSession::metaToFwFocusMode_ = {
57     {OHOS_CAMERA_FOCUS_MODE_MANUAL, FOCUS_MODE_MANUAL},
58     {OHOS_CAMERA_FOCUS_MODE_CONTINUOUS_AUTO, FOCUS_MODE_CONTINUOUS_AUTO},
59     {OHOS_CAMERA_FOCUS_MODE_AUTO, FOCUS_MODE_AUTO},
60     {OHOS_CAMERA_FOCUS_MODE_LOCKED, FOCUS_MODE_LOCKED}
61 };
62 
63 const std::unordered_map<FocusMode, camera_focus_mode_enum_t> CaptureSession::fwToMetaFocusMode_ = {
64     {FOCUS_MODE_MANUAL, OHOS_CAMERA_FOCUS_MODE_MANUAL},
65     {FOCUS_MODE_CONTINUOUS_AUTO, OHOS_CAMERA_FOCUS_MODE_CONTINUOUS_AUTO},
66     {FOCUS_MODE_AUTO, OHOS_CAMERA_FOCUS_MODE_AUTO},
67     {FOCUS_MODE_LOCKED, OHOS_CAMERA_FOCUS_MODE_LOCKED}
68 };
69 
70 const std::unordered_map<camera_flash_mode_enum_t, FlashMode> CaptureSession::metaToFwFlashMode_ = {
71     {OHOS_CAMERA_FLASH_MODE_CLOSE, FLASH_MODE_CLOSE},
72     {OHOS_CAMERA_FLASH_MODE_OPEN, FLASH_MODE_OPEN},
73     {OHOS_CAMERA_FLASH_MODE_AUTO, FLASH_MODE_AUTO},
74     {OHOS_CAMERA_FLASH_MODE_ALWAYS_OPEN, FLASH_MODE_ALWAYS_OPEN}
75 };
76 
77 const std::unordered_map<FlashMode, camera_flash_mode_enum_t> CaptureSession::fwToMetaFlashMode_ = {
78     {FLASH_MODE_CLOSE, OHOS_CAMERA_FLASH_MODE_CLOSE},
79     {FLASH_MODE_OPEN, OHOS_CAMERA_FLASH_MODE_OPEN},
80     {FLASH_MODE_AUTO, OHOS_CAMERA_FLASH_MODE_AUTO},
81     {FLASH_MODE_ALWAYS_OPEN, OHOS_CAMERA_FLASH_MODE_ALWAYS_OPEN}
82 };
83 
84 const std::unordered_map<CameraVideoStabilizationMode,
85 VideoStabilizationMode> CaptureSession::metaToFwVideoStabModes_ = {
86     {OHOS_CAMERA_VIDEO_STABILIZATION_OFF, OFF},
87     {OHOS_CAMERA_VIDEO_STABILIZATION_LOW, LOW},
88     {OHOS_CAMERA_VIDEO_STABILIZATION_MIDDLE, MIDDLE},
89     {OHOS_CAMERA_VIDEO_STABILIZATION_HIGH, HIGH},
90     {OHOS_CAMERA_VIDEO_STABILIZATION_AUTO, AUTO}
91 };
92 
93 const std::unordered_map<VideoStabilizationMode,
94 CameraVideoStabilizationMode> CaptureSession::fwToMetaVideoStabModes_ = {
95     {OFF, OHOS_CAMERA_VIDEO_STABILIZATION_OFF},
96     {LOW, OHOS_CAMERA_VIDEO_STABILIZATION_LOW},
97     {MIDDLE, OHOS_CAMERA_VIDEO_STABILIZATION_MIDDLE},
98     {HIGH, OHOS_CAMERA_VIDEO_STABILIZATION_HIGH},
99     {AUTO, OHOS_CAMERA_VIDEO_STABILIZATION_AUTO}
100 };
101 
102 class CaptureSessionCallback : public HCaptureSessionCallbackStub {
103 public:
104     sptr<CaptureSession> captureSession_ = nullptr;
CaptureSessionCallback()105     CaptureSessionCallback() : captureSession_(nullptr) {
106     }
107 
CaptureSessionCallback(const sptr<CaptureSession> & captureSession)108     explicit CaptureSessionCallback(const sptr<CaptureSession> &captureSession) : captureSession_(captureSession) {
109     }
110 
~CaptureSessionCallback()111     ~CaptureSessionCallback()
112     {
113         captureSession_ = nullptr;
114     }
115 
OnError(int32_t errorCode)116     int32_t OnError(int32_t errorCode) override
117     {
118         MEDIA_INFO_LOG("CaptureSessionCallback::OnError() is called!, errorCode: %{public}d",
119                        errorCode);
120         if (captureSession_ != nullptr && captureSession_->GetApplicationCallback() != nullptr) {
121             captureSession_->GetApplicationCallback()->OnError(errorCode);
122         } else {
123             MEDIA_INFO_LOG("CaptureSessionCallback::ApplicationCallback not set!, Discarding callback");
124         }
125         return CameraErrorCode::SUCCESS;
126     }
127 };
128 
CaptureSession(sptr<ICaptureSession> & captureSession)129 CaptureSession::CaptureSession(sptr<ICaptureSession> &captureSession)
130 {
131     captureSession_ = captureSession;
132     inputDevice_ = nullptr;
133 }
134 
~CaptureSession()135 CaptureSession::~CaptureSession()
136 {
137     inputDevice_ = nullptr;
138     captureSession_ = nullptr;
139     changedMetadata_ = nullptr;
140     appCallback_ = nullptr;
141     captureSessionCallback_ = nullptr;
142     exposureCallback_ = nullptr;
143     focusCallback_ = nullptr;
144 }
145 
BeginConfig()146 int32_t CaptureSession::BeginConfig()
147 {
148     CAMERA_SYNC_TRACE;
149     if (IsSessionConfiged()) {
150         MEDIA_ERR_LOG("CaptureSession::BeginConfig Session is locked");
151         return CameraErrorCode::SESSION_CONFIG_LOCKED;
152     }
153     int32_t errCode = CAMERA_UNKNOWN_ERROR;
154     if (captureSession_) {
155         errCode = captureSession_->BeginConfig();
156         if (errCode != CAMERA_OK) {
157             MEDIA_ERR_LOG("Failed to BeginConfig!, %{public}d", errCode);
158         }
159     } else {
160         MEDIA_ERR_LOG("CaptureSession::BeginConfig() captureSession_ is nullptr");
161     }
162     return ServiceToCameraError(errCode);
163 }
164 
CommitConfig()165 int32_t CaptureSession::CommitConfig()
166 {
167     CAMERA_SYNC_TRACE;
168     if (!IsSessionConfiged()) {
169         MEDIA_ERR_LOG("CaptureSession::CommitConfig operation Not allowed!");
170         return CameraErrorCode::OPERATION_NOT_ALLOWED;
171     }
172     int32_t errCode = CAMERA_UNKNOWN_ERROR;
173     if (captureSession_) {
174         errCode = captureSession_->CommitConfig();
175         if (errCode != CAMERA_OK) {
176             MEDIA_ERR_LOG("Failed to CommitConfig!, %{public}d", errCode);
177         }
178     } else {
179         MEDIA_ERR_LOG("CaptureSession::CommitConfig() captureSession_ is nullptr");
180     }
181     return ServiceToCameraError(errCode);
182 }
183 
CanAddInput(sptr<CaptureInput> & input)184 int32_t CaptureSession::CanAddInput(sptr<CaptureInput> &input)
185 {
186     // todo: get Profile passed to createOutput and compare with OutputCapability
187     // if present in capability return ok.
188     return CameraErrorCode::SUCCESS;
189 }
190 
AddInput(sptr<CaptureInput> & input)191 int32_t CaptureSession::AddInput(sptr<CaptureInput> &input)
192 {
193     CAMERA_SYNC_TRACE;
194     if (!IsSessionConfiged()) {
195         MEDIA_ERR_LOG("CaptureSession::AddInput operation Not allowed!");
196         return CameraErrorCode::OPERATION_NOT_ALLOWED;
197     }
198     if (input == nullptr) {
199         MEDIA_ERR_LOG("CaptureSession::AddInput input is null");
200         return ServiceToCameraError(CAMERA_INVALID_ARG);
201     }
202     input->SetSession(this);
203     inputDevice_ = input;
204     int32_t errCode = CAMERA_UNKNOWN_ERROR;
205     if (captureSession_) {
206         errCode = captureSession_->AddInput(((sptr<CameraInput> &)input)->GetCameraDevice());
207         if (errCode != CAMERA_OK) {
208             MEDIA_ERR_LOG("Failed to AddInput!, %{public}d", errCode);
209         }
210     } else {
211         MEDIA_ERR_LOG("CaptureSession::AddInput() captureSession_ is nullptr");
212     }
213     return ServiceToCameraError(errCode);
214 }
215 
CanAddOutput(sptr<CaptureOutput> & output)216 int32_t CaptureSession::CanAddOutput(sptr<CaptureOutput> &output)
217 {
218     // todo: get Profile passed to createOutput and compare with OutputCapability
219     // if present in capability return ok.
220     return CameraErrorCode::SUCCESS;
221 }
222 
AddOutput(sptr<CaptureOutput> & output)223 int32_t CaptureSession::AddOutput(sptr<CaptureOutput> &output)
224 {
225     CAMERA_SYNC_TRACE;
226     if (!IsSessionConfiged()) {
227         MEDIA_ERR_LOG("CaptureSession::AddOutput operation Not allowed!");
228         return CameraErrorCode::OPERATION_NOT_ALLOWED;
229     }
230     if (output == nullptr) {
231         MEDIA_ERR_LOG("CaptureSession::AddOutput output is null");
232         return ServiceToCameraError(CAMERA_INVALID_ARG);
233     }
234     output->SetSession(this);
235     if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_VIDEO) {
236         SetFrameRateRange(static_cast<VideoOutput *>(output.GetRefPtr())->GetFrameRateRange());
237     }
238     int32_t errCode = CAMERA_UNKNOWN_ERROR;
239     if (captureSession_) {
240         errCode = captureSession_->AddOutput(output->GetStreamType(), output->GetStream());
241         if (errCode != CAMERA_OK) {
242             MEDIA_ERR_LOG("Failed to AddOutput!, %{public}d", errCode);
243         }
244     } else {
245         MEDIA_ERR_LOG("CaptureSession::AddOutput() captureSession_ is nullptr");
246     }
247     return ServiceToCameraError(errCode);
248 }
249 
RemoveInput(sptr<CaptureInput> & input)250 int32_t CaptureSession::RemoveInput(sptr<CaptureInput> &input)
251 {
252     CAMERA_SYNC_TRACE;
253     if (!IsSessionConfiged()) {
254         MEDIA_ERR_LOG("CaptureSession::RemoveInput operation Not allowed!");
255         return CameraErrorCode::OPERATION_NOT_ALLOWED;
256     }
257     if (input == nullptr) {
258         MEDIA_ERR_LOG("CaptureSession::RemoveInput input is null");
259         return ServiceToCameraError(CAMERA_INVALID_ARG);
260     }
261     if (inputDevice_ != nullptr) {
262         inputDevice_ = nullptr;
263     }
264     int32_t errCode = CAMERA_UNKNOWN_ERROR;
265     if (captureSession_) {
266         errCode = captureSession_->RemoveInput(((sptr<CameraInput> &)input)->GetCameraDevice());
267         if (errCode != CAMERA_OK) {
268             MEDIA_ERR_LOG("Failed to RemoveInput!, %{public}d", errCode);
269         }
270     } else {
271         MEDIA_ERR_LOG("CaptureSession::RemoveInput() captureSession_ is nullptr");
272     }
273     return ServiceToCameraError(errCode);
274 }
275 
RemoveOutput(sptr<CaptureOutput> & output)276 int32_t CaptureSession::RemoveOutput(sptr<CaptureOutput> &output)
277 {
278     CAMERA_SYNC_TRACE;
279     if (!IsSessionConfiged()) {
280         MEDIA_ERR_LOG("CaptureSession::RemoveOutput operation Not allowed!");
281         return CameraErrorCode::OPERATION_NOT_ALLOWED;
282     }
283     if (output == nullptr) {
284         MEDIA_ERR_LOG("CaptureSession::RemoveOutput output is null");
285         return ServiceToCameraError(CAMERA_INVALID_ARG);
286     }
287     output->SetSession(nullptr);
288     int32_t errCode = CAMERA_UNKNOWN_ERROR;
289     if (captureSession_) {
290         errCode = captureSession_->RemoveOutput(output->GetStreamType(), output->GetStream());
291         if (errCode != CAMERA_OK) {
292             MEDIA_ERR_LOG("Failed to RemoveOutput!, %{public}d", errCode);
293         }
294     } else {
295         MEDIA_ERR_LOG("CaptureSession::RemoveOutput() captureSession_ is nullptr");
296     }
297     return ServiceToCameraError(errCode);
298 }
299 
Start()300 int32_t CaptureSession::Start()
301 {
302     CAMERA_SYNC_TRACE;
303     if (!IsSessionCommited()) {
304         MEDIA_ERR_LOG("CaptureSession::Start Session not Commited");
305         return CameraErrorCode::SESSION_NOT_CONFIG;
306     }
307     int32_t errCode = CAMERA_UNKNOWN_ERROR;
308     if (captureSession_) {
309         errCode = captureSession_->Start();
310         if (errCode != CAMERA_OK) {
311             MEDIA_ERR_LOG("Failed to Start capture session!, %{public}d", errCode);
312         }
313     } else {
314         MEDIA_ERR_LOG("CaptureSession::Start() captureSession_ is nullptr");
315     }
316     return ServiceToCameraError(errCode);
317 }
318 
Stop()319 int32_t CaptureSession::Stop()
320 {
321     CAMERA_SYNC_TRACE;
322     int32_t errCode = CAMERA_UNKNOWN_ERROR;
323     if (captureSession_) {
324         errCode = captureSession_->Stop();
325         if (errCode != CAMERA_OK) {
326             MEDIA_ERR_LOG("Failed to Stop capture session!, %{public}d", errCode);
327         }
328     } else {
329         MEDIA_ERR_LOG("CaptureSession::Stop() captureSession_ is nullptr");
330     }
331     return ServiceToCameraError(errCode);
332 }
333 
Release()334 int32_t CaptureSession::Release()
335 {
336     CAMERA_SYNC_TRACE;
337     int32_t errCode = CAMERA_UNKNOWN_ERROR;
338     if (captureSession_) {
339         errCode = captureSession_->Release(0);
340         if (errCode != CAMERA_OK) {
341             MEDIA_ERR_LOG("Failed to Release capture session!, %{public}d", errCode);
342         }
343     } else {
344         MEDIA_ERR_LOG("CaptureSession::Release() captureSession_ is nullptr");
345     }
346     inputDevice_ = nullptr;
347     captureSession_ = nullptr;
348     captureSessionCallback_ = nullptr;
349     changedMetadata_ = nullptr;
350     appCallback_ = nullptr;
351     exposureCallback_ = nullptr;
352     focusCallback_ = nullptr;
353     return ServiceToCameraError(errCode);
354 }
355 
SetCallback(std::shared_ptr<SessionCallback> callback)356 void CaptureSession::SetCallback(std::shared_ptr<SessionCallback> callback)
357 {
358     if (callback == nullptr) {
359         MEDIA_ERR_LOG("CaptureSession::SetCallback: Unregistering application callback!");
360     }
361     int32_t errorCode = CAMERA_OK;
362 
363     appCallback_ = callback;
364     if (appCallback_ != nullptr && captureSession_ != nullptr) {
365         if (captureSessionCallback_ == nullptr) {
366             captureSessionCallback_ = new(std::nothrow) CaptureSessionCallback(this);
367         }
368         if (captureSession_) {
369             errorCode = captureSession_->SetCallback(captureSessionCallback_);
370             if (errorCode != CAMERA_OK) {
371                 MEDIA_ERR_LOG("CaptureSession::SetCallback: Failed to register callback, errorCode: %{public}d",
372                     errorCode);
373                 captureSessionCallback_ = nullptr;
374                 appCallback_ = nullptr;
375             }
376         } else {
377             MEDIA_ERR_LOG("CaptureSession::SetCallback() captureSession_ is nullptr");
378         }
379     }
380     return;
381 }
382 
GetApplicationCallback()383 std::shared_ptr<SessionCallback> CaptureSession::GetApplicationCallback()
384 {
385     return appCallback_;
386 }
387 
UpdateSetting(std::shared_ptr<Camera::CameraMetadata> changedMetadata)388 int32_t CaptureSession::UpdateSetting(std::shared_ptr<Camera::CameraMetadata> changedMetadata)
389 {
390     CAMERA_SYNC_TRACE;
391     if (!Camera::GetCameraMetadataItemCount(changedMetadata->get())) {
392         MEDIA_INFO_LOG("CaptureSession::UpdateSetting No configuration to update");
393         return CameraErrorCode::SUCCESS;
394     }
395 
396     if (!IsSessionCommited()) {
397         MEDIA_ERR_LOG("CaptureSession::UpdateSetting Failed Session Not Commited");
398         return CameraErrorCode::SESSION_NOT_CONFIG;
399     }
400     if (!inputDevice_ || !((sptr<CameraInput> &)inputDevice_)->GetCameraDevice()) {
401         MEDIA_ERR_LOG("CaptureSession::UpdateSetting Failed inputDevice_ is nullptr");
402         return CameraErrorCode::SUCCESS;
403     }
404     int32_t ret = ((sptr<CameraInput> &)inputDevice_)->GetCameraDevice()->UpdateSetting(changedMetadata);
405     if (ret != CAMERA_OK) {
406         MEDIA_ERR_LOG("CaptureSession::UpdateSetting Failed to update settings, errCode = %{public}d", ret);
407         return ServiceToCameraError(ret);
408     }
409 
410     uint32_t count = changedMetadata->get()->item_count;
411     uint8_t* data = Camera::GetMetadataData(changedMetadata->get());
412     camera_metadata_item_entry_t* itemEntry = Camera::GetMetadataItems(changedMetadata->get());
413     std::shared_ptr<Camera::CameraMetadata> baseMetadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
414     for (uint32_t i = 0; i < count; i++, itemEntry++) {
415         bool status = false;
416         camera_metadata_item_t item;
417         size_t length = Camera::CalculateCameraMetadataItemDataSize(itemEntry->data_type, itemEntry->count);
418         ret = Camera::FindCameraMetadataItem(baseMetadata->get(), itemEntry->item, &item);
419         if (ret == CAM_META_SUCCESS) {
420             status = baseMetadata->updateEntry(itemEntry->item,
421                                                (length == 0) ? itemEntry->data.value : (data + itemEntry->data.offset),
422                                                itemEntry->count);
423         } else if (ret == CAM_META_ITEM_NOT_FOUND) {
424             status = baseMetadata->addEntry(itemEntry->item,
425                                             (length == 0) ? itemEntry->data.value : (data + itemEntry->data.offset),
426                                             itemEntry->count);
427         }
428         if (!status) {
429             MEDIA_ERR_LOG("CaptureSession::UpdateSetting Failed to add/update metadata item: %{public}d",
430                           itemEntry->item);
431         }
432     }
433     return CameraErrorCode::SUCCESS;
434 }
435 
LockForControl()436 void CaptureSession::LockForControl()
437 {
438     changeMetaMutex_.lock();
439     MEDIA_DEBUG_LOG("CaptureSession::LockForControl Called");
440     changedMetadata_ = std::make_shared<Camera::CameraMetadata>(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH);
441 }
442 
UnlockForControl()443 int32_t CaptureSession::UnlockForControl()
444 {
445     if (changedMetadata_ == nullptr) {
446         MEDIA_ERR_LOG("CaptureSession::UnlockForControl Need to call LockForControl() before UnlockForControl()");
447         return ServiceToCameraError(CAMERA_INVALID_ARG);
448     }
449     MEDIA_DEBUG_LOG("CaptureSession::UnlockForControl Called");
450     UpdateSetting(changedMetadata_);
451     changedMetadata_ = nullptr;
452     changeMetaMutex_.unlock();
453     return CameraErrorCode::SUCCESS;
454 }
455 
GetActiveVideoStabilizationMode()456 VideoStabilizationMode CaptureSession::GetActiveVideoStabilizationMode()
457 {
458     sptr<CameraDevice> cameraObj_;
459     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
460         MEDIA_ERR_LOG("CaptureSession::GetActiveVideoStabilizationMode camera device is null");
461         return OFF;
462     }
463     cameraObj_ = inputDevice_->GetCameraDeviceInfo();
464     std::shared_ptr<Camera::CameraMetadata> metadata = cameraObj_->GetMetadata();
465     camera_metadata_item_t item;
466     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &item);
467     if (ret == CAM_META_SUCCESS) {
468         auto itr = metaToFwVideoStabModes_.find(static_cast<CameraVideoStabilizationMode>(item.data.u8[0]));
469         if (itr != metaToFwVideoStabModes_.end()) {
470             return itr->second;
471         }
472     }
473     return OFF;
474 }
475 
GetActiveVideoStabilizationMode(VideoStabilizationMode & mode)476 int32_t CaptureSession::GetActiveVideoStabilizationMode(VideoStabilizationMode &mode)
477 {
478     if (!IsSessionCommited()) {
479         MEDIA_ERR_LOG("CaptureSession::GetActiveVideoStabilizationMode Session is not Commited");
480         return CameraErrorCode::SESSION_NOT_CONFIG;
481     }
482     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
483         MEDIA_ERR_LOG("CaptureSession::GetActiveVideoStabilizationMode camera device is null");
484         return CameraErrorCode::SUCCESS;
485     }
486     mode = OFF;
487     bool isSupported = false;
488     sptr<CameraDevice> cameraObj_;
489     cameraObj_ = inputDevice_->GetCameraDeviceInfo();
490     std::shared_ptr<Camera::CameraMetadata> metadata = cameraObj_->GetMetadata();
491     camera_metadata_item_t item;
492     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &item);
493     if (ret == CAM_META_SUCCESS) {
494         auto itr = metaToFwVideoStabModes_.find(static_cast<CameraVideoStabilizationMode>(item.data.u8[0]));
495         if (itr != metaToFwVideoStabModes_.end()) {
496             mode = itr->second;
497             isSupported = true;
498         }
499     }
500     if (!isSupported || ret != CAM_META_SUCCESS) {
501         MEDIA_ERR_LOG("CaptureSession::GetActiveVideoStabilizationMode Failed with return code %{public}d", ret);
502     }
503     return CameraErrorCode::SUCCESS;
504 }
505 
SetVideoStabilizationMode(VideoStabilizationMode stabilizationMode)506 int32_t CaptureSession::SetVideoStabilizationMode(VideoStabilizationMode stabilizationMode)
507 {
508     if (!IsSessionCommited()) {
509         MEDIA_ERR_LOG("CaptureSession::SetVideoStabilizationMode Session is not Commited");
510         return CameraErrorCode::SESSION_NOT_CONFIG;
511     }
512     auto itr = fwToMetaVideoStabModes_.find(stabilizationMode);
513     if ((itr == fwToMetaVideoStabModes_.end()) || !IsVideoStabilizationModeSupported(stabilizationMode)) {
514         MEDIA_ERR_LOG("CaptureSession::SetVideoStabilizationMode Mode: %{public}d not supported", stabilizationMode);
515         stabilizationMode = OFF;
516     }
517 
518     uint32_t count = 1;
519     uint8_t stabilizationMode_ = stabilizationMode;
520 
521     this->LockForControl();
522     MEDIA_DEBUG_LOG("CaptureSession::SetVideoStabilizingMode StabilizationMode : %{public}d", stabilizationMode_);
523     if (!(this->changedMetadata_->addEntry(OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &stabilizationMode_, count))) {
524         MEDIA_DEBUG_LOG("CaptureSession::SetVideoStabilizingMode Failed to set video stabilization mode");
525     }
526 
527     int32_t errCode = this->UnlockForControl();
528     if (errCode != CameraErrorCode::SUCCESS) {
529         MEDIA_DEBUG_LOG("CaptureSession::SetVideoStabilizingMode Failed to set video stabilization mode");
530     }
531     return CameraErrorCode::SUCCESS;
532 }
533 
IsVideoStabilizationModeSupported(VideoStabilizationMode stabilizationMode)534 bool CaptureSession::IsVideoStabilizationModeSupported(VideoStabilizationMode stabilizationMode)
535 {
536     std::vector<VideoStabilizationMode> stabilizationModes = GetSupportedStabilizationMode();
537     if (std::find(stabilizationModes.begin(), stabilizationModes.end(), stabilizationMode)
538        != stabilizationModes.end()) {
539         return true;
540     }
541     return false;
542 }
543 
IsVideoStabilizationModeSupported(VideoStabilizationMode stabilizationMode,bool & isSupported)544 int32_t CaptureSession::IsVideoStabilizationModeSupported(VideoStabilizationMode stabilizationMode, bool &isSupported)
545 {
546     if (!IsSessionCommited()) {
547         MEDIA_ERR_LOG("CaptureSession::IsVideoStabilizationModeSupported Session is not Commited");
548         return CameraErrorCode::SESSION_NOT_CONFIG;
549     }
550     std::vector<VideoStabilizationMode> stabilizationModes = GetSupportedStabilizationMode();
551     if (std::find(stabilizationModes.begin(), stabilizationModes.end(), stabilizationMode)
552        != stabilizationModes.end()) {
553         isSupported = true;
554         return CameraErrorCode::SUCCESS;
555     }
556     isSupported = false;
557     return CameraErrorCode::SUCCESS;
558 }
559 
GetSupportedStabilizationMode()560 std::vector<VideoStabilizationMode> CaptureSession::GetSupportedStabilizationMode()
561 {
562     std::vector<VideoStabilizationMode> stabilizationModes;
563 
564     sptr<CameraDevice> cameraObj_;
565     if (!IsSessionCommited()) {
566         MEDIA_ERR_LOG("CaptureSession::GetSupportedStabilizationMode Session is not Commited");
567         return stabilizationModes;
568     }
569     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
570         MEDIA_ERR_LOG("CaptureSession::GetSupportedStabilizationMode camera device is null");
571         return stabilizationModes;
572     }
573     cameraObj_ = inputDevice_->GetCameraDeviceInfo();
574     std::shared_ptr<Camera::CameraMetadata> metadata = cameraObj_->GetMetadata();
575     camera_metadata_item_t item;
576     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_VIDEO_STABILIZATION_MODES, &item);
577     if (ret != CAM_META_SUCCESS) {
578         MEDIA_ERR_LOG("CaptureSession::GetSupporteStabilizationModes Failed with return code %{public}d", ret);
579         return stabilizationModes;
580     }
581 
582     for (uint32_t i = 0; i < item.count; i++) {
583         auto itr = metaToFwVideoStabModes_.find(static_cast<CameraVideoStabilizationMode>(item.data.u8[i]));
584         if (itr != metaToFwVideoStabModes_.end()) {
585             stabilizationModes.emplace_back(itr->second);
586         }
587     }
588     return stabilizationModes;
589 }
590 
GetSupportedStabilizationMode(std::vector<VideoStabilizationMode> & stabilizationModes)591 int32_t CaptureSession::GetSupportedStabilizationMode(std::vector<VideoStabilizationMode> &stabilizationModes)
592 {
593     sptr<CameraDevice> cameraObj_;
594     stabilizationModes.clear();
595     if (!IsSessionCommited()) {
596         MEDIA_ERR_LOG("CaptureSession::GetSupportedStabilizationMode Session is not Commited");
597         return CameraErrorCode::SESSION_NOT_CONFIG;
598     }
599     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
600         MEDIA_ERR_LOG("CaptureSession::GetSupportedStabilizationMode camera device is null");
601         return CameraErrorCode::SUCCESS;
602     }
603     cameraObj_ = inputDevice_->GetCameraDeviceInfo();
604     std::shared_ptr<Camera::CameraMetadata> metadata = cameraObj_->GetMetadata();
605     camera_metadata_item_t item;
606     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_VIDEO_STABILIZATION_MODES, &item);
607     if (ret != CAM_META_SUCCESS) {
608         MEDIA_ERR_LOG("CaptureSession::GetSupporteStabilizationModes Failed with return code %{public}d", ret);
609         return CameraErrorCode::SUCCESS;
610     }
611 
612     for (uint32_t i = 0; i < item.count; i++) {
613         auto itr = metaToFwVideoStabModes_.find(static_cast<CameraVideoStabilizationMode>(item.data.u8[i]));
614         if (itr != metaToFwVideoStabModes_.end()) {
615             stabilizationModes.emplace_back(itr->second);
616         }
617     }
618     return CameraErrorCode::SUCCESS;
619 }
620 
IsExposureModeSupported(ExposureMode exposureMode)621 bool CaptureSession::IsExposureModeSupported(ExposureMode exposureMode)
622 {
623     std::vector<ExposureMode> vecSupportedExposureModeList;
624     vecSupportedExposureModeList = this->GetSupportedExposureModes();
625     if (find(vecSupportedExposureModeList.begin(), vecSupportedExposureModeList.end(),
626         exposureMode) != vecSupportedExposureModeList.end()) {
627         return true;
628     }
629 
630     return false;
631 }
632 
IsExposureModeSupported(ExposureMode exposureMode,bool & isSupported)633 int32_t CaptureSession::IsExposureModeSupported(ExposureMode exposureMode, bool &isSupported)
634 {
635     if (!IsSessionCommited()) {
636         MEDIA_ERR_LOG("CaptureSession::IsExposureModeSupported Session is not Commited");
637         return CameraErrorCode::SESSION_NOT_CONFIG;
638     }
639     std::vector<ExposureMode> vecSupportedExposureModeList;
640     vecSupportedExposureModeList = this->GetSupportedExposureModes();
641     if (find(vecSupportedExposureModeList.begin(), vecSupportedExposureModeList.end(),
642         exposureMode) != vecSupportedExposureModeList.end()) {
643         isSupported = true;
644         return CameraErrorCode::SUCCESS;
645     }
646     isSupported = false;
647     return CameraErrorCode::SUCCESS;
648 }
649 
GetSupportedExposureModes()650 std::vector<ExposureMode> CaptureSession::GetSupportedExposureModes()
651 {
652     if (!IsSessionCommited()) {
653         MEDIA_ERR_LOG("CaptureSession::GetSupportedExposureModes Session is not Commited");
654         return {};
655     }
656     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
657         MEDIA_ERR_LOG("CaptureSession::GetSupportedExposureModes camera device is null");
658         return {};
659     }
660     std::vector<ExposureMode> supportedExposureModes;
661     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
662     camera_metadata_item_t item;
663     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_EXPOSURE_MODES, &item);
664     if (ret != CAM_META_SUCCESS) {
665         MEDIA_ERR_LOG("CaptureSession::GetSupportedExposureModes Failed with return code %{public}d", ret);
666         return supportedExposureModes;
667     }
668 
669     for (uint32_t i = 0; i < item.count; i++) {
670         auto itr = metaToFwExposureMode_.find(static_cast<camera_exposure_mode_enum_t>(item.data.u8[i]));
671         if (itr != metaToFwExposureMode_.end()) {
672             supportedExposureModes.emplace_back(itr->second);
673         }
674     }
675     return supportedExposureModes;
676 }
677 
GetSupportedExposureModes(std::vector<ExposureMode> & supportedExposureModes)678 int32_t CaptureSession::GetSupportedExposureModes(std::vector<ExposureMode> &supportedExposureModes)
679 {
680     supportedExposureModes.clear();
681     if (!IsSessionCommited()) {
682         MEDIA_ERR_LOG("CaptureSession::GetSupportedExposureModes Session is not Commited");
683         return CameraErrorCode::SESSION_NOT_CONFIG;
684     }
685     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
686         MEDIA_ERR_LOG("CaptureSession::GetSupportedExposureModes camera device is null");
687         return CameraErrorCode::SUCCESS;
688     }
689     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
690     camera_metadata_item_t item;
691     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_EXPOSURE_MODES, &item);
692     if (ret != CAM_META_SUCCESS) {
693         MEDIA_ERR_LOG("CaptureSession::GetSupportedExposureModes Failed with return code %{public}d", ret);
694         return CameraErrorCode::SUCCESS;
695     }
696 
697     for (uint32_t i = 0; i < item.count; i++) {
698         auto itr = metaToFwExposureMode_.find(static_cast<camera_exposure_mode_enum_t>(item.data.u8[i]));
699         if (itr != metaToFwExposureMode_.end()) {
700             supportedExposureModes.emplace_back(itr->second);
701         }
702     }
703     return CameraErrorCode::SUCCESS;
704 }
705 
SetExposureMode(ExposureMode exposureMode)706 int32_t CaptureSession::SetExposureMode(ExposureMode exposureMode)
707 {
708     CAMERA_SYNC_TRACE;
709     if (!IsSessionCommited()) {
710         MEDIA_ERR_LOG("CaptureSession::SetExposureMode Session is not Commited");
711         return CameraErrorCode::SESSION_NOT_CONFIG;
712     }
713 
714     if (changedMetadata_ == nullptr) {
715         MEDIA_ERR_LOG("CaptureSession::SetExposureMode Need to call LockForControl() "
716                       "before setting camera properties");
717         return CameraErrorCode::SUCCESS;
718     }
719     uint8_t exposure = fwToMetaExposureMode_.at(EXPOSURE_MODE_LOCKED);
720     auto itr = fwToMetaExposureMode_.find(exposureMode);
721     if (itr == fwToMetaExposureMode_.end()) {
722         MEDIA_ERR_LOG("CaptureSession::SetExposureMode Unknown exposure mode");
723     } else {
724         exposure = itr->second;
725     }
726 
727     bool status = false;
728     uint32_t count = 1;
729     camera_metadata_item_t item;
730     int ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_EXPOSURE_MODE, &item);
731     if (ret == CAM_META_ITEM_NOT_FOUND) {
732         status = changedMetadata_->addEntry(OHOS_CONTROL_EXPOSURE_MODE, &exposure, count);
733     } else if (ret == CAM_META_SUCCESS) {
734         status = changedMetadata_->updateEntry(OHOS_CONTROL_EXPOSURE_MODE, &exposure, count);
735     }
736 
737     if (!status) {
738         MEDIA_ERR_LOG("CaptureSession::SetExposureMode Failed to set exposure mode");
739     }
740 
741     return CameraErrorCode::SUCCESS;
742 }
743 
GetExposureMode()744 ExposureMode CaptureSession::GetExposureMode()
745 {
746     if (!IsSessionCommited()) {
747         MEDIA_ERR_LOG("CaptureSession::GetExposureMode Session is not Commited");
748         return EXPOSURE_MODE_UNSUPPORTED;
749     }
750     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
751         MEDIA_ERR_LOG("CaptureSession::GetExposureMode camera device is null");
752         return EXPOSURE_MODE_UNSUPPORTED;
753     }
754     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
755     camera_metadata_item_t item;
756     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_EXPOSURE_MODE, &item);
757     if (ret != CAM_META_SUCCESS) {
758         MEDIA_ERR_LOG("CaptureSession::GetExposureMode Failed with return code %{public}d", ret);
759         return EXPOSURE_MODE_UNSUPPORTED;
760     }
761     auto itr = metaToFwExposureMode_.find(static_cast<camera_exposure_mode_enum_t>(item.data.u8[0]));
762     if (itr != metaToFwExposureMode_.end()) {
763         return itr->second;
764     }
765 
766     return EXPOSURE_MODE_UNSUPPORTED;
767 }
768 
GetExposureMode(ExposureMode & exposureMode)769 int32_t CaptureSession::GetExposureMode(ExposureMode &exposureMode)
770 {
771     exposureMode = EXPOSURE_MODE_UNSUPPORTED;
772     if (!IsSessionCommited()) {
773         MEDIA_ERR_LOG("CaptureSession::GetExposureMode Session is not Commited");
774         return CameraErrorCode::SESSION_NOT_CONFIG;
775     }
776     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
777         MEDIA_ERR_LOG("CaptureSession::GetExposureMode camera device is null");
778         return CameraErrorCode::SUCCESS;
779     }
780     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
781     camera_metadata_item_t item;
782     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_EXPOSURE_MODE, &item);
783     if (ret != CAM_META_SUCCESS) {
784         MEDIA_ERR_LOG("CaptureSession::GetExposureMode Failed with return code %{public}d", ret);
785         return CameraErrorCode::SUCCESS;
786     }
787     auto itr = metaToFwExposureMode_.find(static_cast<camera_exposure_mode_enum_t>(item.data.u8[0]));
788     if (itr != metaToFwExposureMode_.end()) {
789         exposureMode = itr->second;
790         return CameraErrorCode::SUCCESS;
791     }
792     return CameraErrorCode::SUCCESS;
793 }
794 
795 
SetMeteringPoint(Point exposurePoint)796 int32_t CaptureSession::SetMeteringPoint(Point exposurePoint)
797 {
798     if (!IsSessionCommited()) {
799         MEDIA_ERR_LOG("CaptureSession::SetMeteringPoint Session is not Commited");
800         return CameraErrorCode::SESSION_NOT_CONFIG;
801     }
802 
803     if (changedMetadata_ == nullptr) {
804         MEDIA_ERR_LOG("CaptureSession::SetExposurePoint Need to call LockForControl() "
805             "before setting camera properties");
806         return CameraErrorCode::SUCCESS;
807     }
808     Point unifyExposurePoint = CoordinateTransform(exposurePoint);
809     bool status = false;
810     float exposureArea[2] = {unifyExposurePoint.x, unifyExposurePoint.y};
811     camera_metadata_item_t item;
812 
813     int ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_AE_REGIONS, &item);
814     if (ret == CAM_META_ITEM_NOT_FOUND) {
815         status = changedMetadata_->addEntry(OHOS_CONTROL_AE_REGIONS, exposureArea,
816             sizeof(exposureArea) / sizeof(exposureArea[0]));
817     } else if (ret == CAM_META_SUCCESS) {
818         status = changedMetadata_->updateEntry(OHOS_CONTROL_AE_REGIONS, exposureArea,
819             sizeof(exposureArea) / sizeof(exposureArea[0]));
820     }
821 
822     if (!status) {
823         MEDIA_ERR_LOG("CaptureSession::SetExposurePoint Failed to set exposure Area");
824     }
825     return CameraErrorCode::SUCCESS;
826 }
827 
GetMeteringPoint()828 Point CaptureSession::GetMeteringPoint()
829 {
830     Point exposurePoint = {0, 0};
831     if (!IsSessionCommited()) {
832         MEDIA_ERR_LOG("CaptureSession::GetMeteringPoint Session is not Commited");
833         return exposurePoint;
834     }
835     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
836         MEDIA_ERR_LOG("CaptureSession::GetMeteringPoint camera device is null");
837         return exposurePoint;
838     }
839     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
840     camera_metadata_item_t item;
841     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_AE_REGIONS, &item);
842     if (ret != CAM_META_SUCCESS) {
843         MEDIA_ERR_LOG("CaptureSession::GetExposurePoint Failed with return code %{public}d", ret);
844         return exposurePoint;
845     }
846     exposurePoint.x = item.data.f[0];
847     exposurePoint.y = item.data.f[1];
848     Point unifyExposurePoint = CoordinateTransform(exposurePoint);
849     return unifyExposurePoint;
850 }
851 
GetMeteringPoint(Point & exposurePoint)852 int32_t CaptureSession::GetMeteringPoint(Point &exposurePoint)
853 {
854     exposurePoint.x = 0;
855     exposurePoint.y = 0;
856     if (!IsSessionCommited()) {
857         MEDIA_ERR_LOG("CaptureSession::GetMeteringPoint Session is not Commited");
858         return CameraErrorCode::SESSION_NOT_CONFIG;
859     }
860     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
861         MEDIA_ERR_LOG("CaptureSession::GetMeteringPoint camera device is null");
862         return CameraErrorCode::SUCCESS;
863     }
864     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
865     camera_metadata_item_t item;
866     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_AE_REGIONS, &item);
867     if (ret != CAM_META_SUCCESS) {
868         MEDIA_ERR_LOG("CaptureSession::GetExposurePoint Failed with return code %{public}d", ret);
869         return CameraErrorCode::SUCCESS;
870     }
871     exposurePoint.x = item.data.f[0];
872     exposurePoint.y = item.data.f[1];
873     exposurePoint = CoordinateTransform(exposurePoint);
874     return CameraErrorCode::SUCCESS;
875 }
876 
GetExposureBiasRange()877 std::vector<int32_t> CaptureSession::GetExposureBiasRange()
878 {
879     if (!IsSessionCommited()) {
880         MEDIA_ERR_LOG("CaptureSession::GetExposureBiasRange Session is not Commited");
881         return {};
882     }
883     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
884         MEDIA_ERR_LOG("CaptureSession::GetExposureBiasRange camera device is null");
885         return {};
886     }
887     return inputDevice_->GetCameraDeviceInfo()->GetExposureBiasRange();
888 }
889 
GetExposureBiasRange(std::vector<int32_t> & exposureBiasRange)890 int32_t CaptureSession::GetExposureBiasRange(std::vector<int32_t> &exposureBiasRange)
891 {
892     if (!IsSessionCommited()) {
893         MEDIA_ERR_LOG("CaptureSession::GetExposureBiasRange Session is not Commited");
894         return CameraErrorCode::SESSION_NOT_CONFIG;
895     }
896     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
897         MEDIA_ERR_LOG("CaptureSession::GetExposureBiasRange camera device is null");
898         return CameraErrorCode::SUCCESS;
899     }
900     exposureBiasRange = inputDevice_->GetCameraDeviceInfo()->GetExposureBiasRange();
901     return CameraErrorCode::SUCCESS;
902 }
903 
904 
SetExposureBias(int32_t exposureValue)905 int32_t CaptureSession::SetExposureBias(int32_t exposureValue)
906 {
907     if (!IsSessionCommited()) {
908         MEDIA_ERR_LOG("CaptureSession::SetExposureBias Session is not Commited");
909         return CameraErrorCode::SESSION_NOT_CONFIG;
910     }
911     if (changedMetadata_ == nullptr) {
912         MEDIA_ERR_LOG("CaptureSession::SetExposureValue Need to call LockForControl() "
913             "before setting camera properties");
914         return CameraErrorCode::SUCCESS;
915     }
916     bool status = false;
917     int32_t ret;
918     int32_t minIndex = 0;
919     int32_t maxIndex = 1;
920     int32_t count = 1;
921     camera_metadata_item_t item;
922     MEDIA_DEBUG_LOG("CaptureSession::SetExposureValue exposure compensation: %{public}d", exposureValue);
923     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
924         MEDIA_ERR_LOG("CaptureSession::SetExposureBias camera device is null");
925         return CameraErrorCode::SUCCESS;
926     }
927     std::vector<int32_t> biasRange = inputDevice_->GetCameraDeviceInfo()->GetExposureBiasRange();
928     if (biasRange.empty()) {
929         MEDIA_ERR_LOG("CaptureSession::SetExposureValue Bias range is empty");
930         return CameraErrorCode::SUCCESS;
931     }
932     if (exposureValue < biasRange[minIndex]) {
933         MEDIA_DEBUG_LOG("CaptureSession::SetExposureValue bias value:"
934                         "%{public}d is lesser than minimum bias: %{public}d", exposureValue, biasRange[minIndex]);
935         exposureValue = biasRange[minIndex];
936     } else if (exposureValue > biasRange[maxIndex]) {
937         MEDIA_DEBUG_LOG("CaptureSession::SetExposureValue bias value: "
938                         "%{public}d is greater than maximum bias: %{public}d", exposureValue, biasRange[maxIndex]);
939         exposureValue = biasRange[maxIndex];
940     }
941     if (exposureValue == 0) {
942         MEDIA_ERR_LOG("CaptureSession::SetExposureValue Invalid exposure compensation value");
943         return CameraErrorCode::SUCCESS;
944     }
945     ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &item);
946     if (ret == CAM_META_ITEM_NOT_FOUND) {
947         status = changedMetadata_->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &exposureValue, count);
948     } else if (ret == CAM_META_SUCCESS) {
949         status = changedMetadata_->updateEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &exposureValue, count);
950     }
951     if (!status) {
952         MEDIA_ERR_LOG("CaptureSession::SetExposureValue Failed to set exposure compensation");
953     }
954     return CameraErrorCode::SUCCESS;
955 }
956 
GetExposureValue()957 int32_t CaptureSession::GetExposureValue()
958 {
959     if (!IsSessionCommited()) {
960         MEDIA_ERR_LOG("CaptureSession::GetExposureValue Session is not Commited");
961         return 0;
962     }
963     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
964         MEDIA_ERR_LOG("CaptureSession::GetExposureValue camera device is null");
965         return 0;
966     }
967     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
968     camera_metadata_item_t item;
969     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &item);
970     if (ret != CAM_META_SUCCESS) {
971         MEDIA_ERR_LOG("CaptureSession::GetExposureValue Failed with return code %{public}d", ret);
972         return 0;
973     }
974     return static_cast<int32_t>(item.data.i32[0]);
975 }
976 
GetExposureValue(int32_t & exposureValue)977 int32_t CaptureSession::GetExposureValue(int32_t &exposureValue)
978 {
979     if (!IsSessionCommited()) {
980         MEDIA_ERR_LOG("CaptureSession::GetExposureValue Session is not Commited");
981         return CameraErrorCode::SESSION_NOT_CONFIG;
982     }
983     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
984         MEDIA_ERR_LOG("CaptureSession::GetExposureValue camera device is null");
985         return CameraErrorCode::SUCCESS;
986     }
987     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
988     camera_metadata_item_t item;
989     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &item);
990     if (ret != CAM_META_SUCCESS) {
991         MEDIA_ERR_LOG("CaptureSession::GetExposureValue Failed with return code %{public}d", ret);
992         return CameraErrorCode::SUCCESS;
993     }
994     exposureValue = static_cast<int32_t>(item.data.i32[0]);
995     return CameraErrorCode::SUCCESS;
996 }
997 
SetExposureCallback(std::shared_ptr<ExposureCallback> exposureCallback)998 void CaptureSession::SetExposureCallback(std::shared_ptr<ExposureCallback> exposureCallback)
999 {
1000     exposureCallback_ = exposureCallback;
1001 }
1002 
ProcessAutoExposureUpdates(const std::shared_ptr<Camera::CameraMetadata> & result)1003 void CaptureSession::ProcessAutoExposureUpdates(const std::shared_ptr<Camera::CameraMetadata> &result)
1004 {
1005     camera_metadata_item_t item;
1006     common_metadata_header_t* metadata = result->get();
1007 
1008     int ret = Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_EXPOSURE_MODE, &item);
1009     if (ret == CAM_META_SUCCESS) {
1010         MEDIA_DEBUG_LOG("exposure mode: %{public}d", item.data.u8[0]);
1011     }
1012 
1013     ret = Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_EXPOSURE_STATE, &item);
1014     if (ret == CAM_META_SUCCESS) {
1015         MEDIA_INFO_LOG("Exposure state: %{public}d", item.data.u8[0]);
1016         if (exposureCallback_ != nullptr) {
1017             auto itr = metaToFwExposureState_.find(static_cast<camera_exposure_state_t>(item.data.u8[0]));
1018             if (itr != metaToFwExposureState_.end()) {
1019                 exposureCallback_->OnExposureState(itr->second);
1020             }
1021         }
1022     }
1023 }
1024 
GetSupportedFocusModes()1025 std::vector<FocusMode> CaptureSession::GetSupportedFocusModes()
1026 {
1027     std::vector<FocusMode> supportedFocusModes = {};
1028     if (!IsSessionCommited()) {
1029         MEDIA_ERR_LOG("CaptureSession::SetExposureBias Session is not Commited");
1030         return supportedFocusModes;
1031     }
1032     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1033         MEDIA_ERR_LOG("CaptureSession::GetSupportedFocusModes camera device is null");
1034         return supportedFocusModes;
1035     }
1036     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1037     camera_metadata_item_t item;
1038     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FOCUS_MODES, &item);
1039     if (ret != CAM_META_SUCCESS) {
1040         MEDIA_ERR_LOG("CaptureSession::GetSupportedFocusModes Failed with return code %{public}d", ret);
1041         return supportedFocusModes;
1042     }
1043     for (uint32_t i = 0; i < item.count; i++) {
1044         auto itr = metaToFwFocusMode_.find(static_cast<camera_focus_mode_enum_t>(item.data.u8[i]));
1045         if (itr != metaToFwFocusMode_.end()) {
1046             supportedFocusModes.emplace_back(itr->second);
1047         }
1048     }
1049     return supportedFocusModes;
1050 }
1051 
GetSupportedFocusModes(std::vector<FocusMode> & supportedFocusModes)1052 int32_t CaptureSession::GetSupportedFocusModes(std::vector<FocusMode> &supportedFocusModes)
1053 {
1054     supportedFocusModes.clear();
1055     if (!IsSessionCommited()) {
1056         MEDIA_ERR_LOG("CaptureSession::SetExposureBias Session is not Commited");
1057         return CameraErrorCode::SESSION_NOT_CONFIG;
1058     }
1059     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1060         MEDIA_ERR_LOG("CaptureSession::GetSupportedFocusModes camera device is null");
1061         return CameraErrorCode::SUCCESS;
1062     }
1063     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1064     camera_metadata_item_t item;
1065     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FOCUS_MODES, &item);
1066     if (ret != CAM_META_SUCCESS) {
1067         MEDIA_ERR_LOG("CaptureSession::GetSupportedFocusModes Failed with return code %{public}d", ret);
1068         return CameraErrorCode::SUCCESS;
1069     }
1070     for (uint32_t i = 0; i < item.count; i++) {
1071         auto itr = metaToFwFocusMode_.find(static_cast<camera_focus_mode_enum_t>(item.data.u8[i]));
1072         if (itr != metaToFwFocusMode_.end()) {
1073             supportedFocusModes.emplace_back(itr->second);
1074             return CameraErrorCode::SUCCESS;
1075         }
1076     }
1077     return CameraErrorCode::SUCCESS;
1078 }
1079 
SetFocusCallback(std::shared_ptr<FocusCallback> focusCallback)1080 void CaptureSession::SetFocusCallback(std::shared_ptr<FocusCallback> focusCallback)
1081 {
1082     focusCallback_ = focusCallback;
1083     return;
1084 }
1085 
IsFocusModeSupported(FocusMode focusMode)1086 bool CaptureSession::IsFocusModeSupported(FocusMode focusMode)
1087 {
1088     std::vector<FocusMode> vecSupportedFocusModeList;
1089     vecSupportedFocusModeList = this->GetSupportedFocusModes();
1090     if (find(vecSupportedFocusModeList.begin(), vecSupportedFocusModeList.end(),
1091         focusMode) != vecSupportedFocusModeList.end()) {
1092         return true;
1093     }
1094 
1095     return false;
1096 }
1097 
IsFocusModeSupported(FocusMode focusMode,bool & isSupported)1098 int32_t CaptureSession::IsFocusModeSupported(FocusMode focusMode, bool &isSupported)
1099 {
1100     if (!IsSessionCommited()) {
1101         MEDIA_ERR_LOG("CaptureSession::SetExposureBias Session is not Commited");
1102         return CameraErrorCode::SESSION_NOT_CONFIG;
1103     }
1104     std::vector<FocusMode> vecSupportedFocusModeList;
1105     vecSupportedFocusModeList = this->GetSupportedFocusModes();
1106     if (find(vecSupportedFocusModeList.begin(), vecSupportedFocusModeList.end(),
1107         focusMode) != vecSupportedFocusModeList.end()) {
1108         isSupported = true;
1109         return CameraErrorCode::SUCCESS;
1110     }
1111     isSupported = false;
1112     return CameraErrorCode::SUCCESS;
1113 }
1114 
StartFocus(FocusMode focusMode)1115 int32_t CaptureSession::StartFocus(FocusMode focusMode)
1116 {
1117     bool status = false;
1118     int32_t ret;
1119     static int32_t triggerId = 0;
1120     uint32_t count = 1;
1121     uint8_t trigger = OHOS_CAMERA_AF_TRIGGER_START;
1122     camera_metadata_item_t item;
1123 
1124     if (focusMode == FOCUS_MODE_MANUAL) {
1125         return CameraErrorCode::SUCCESS;
1126     }
1127 
1128     ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_AF_TRIGGER, &item);
1129     if (ret == CAM_META_ITEM_NOT_FOUND) {
1130         status = changedMetadata_->addEntry(OHOS_CONTROL_AF_TRIGGER, &trigger, count);
1131     } else if (ret == CAM_META_SUCCESS) {
1132         status = changedMetadata_->updateEntry(OHOS_CONTROL_AF_TRIGGER, &trigger, count);
1133     }
1134 
1135     if (!status) {
1136         MEDIA_ERR_LOG("CaptureSession::StartFocus Failed to set trigger");
1137         return CameraErrorCode::SUCCESS;
1138     }
1139 
1140     triggerId++;
1141     ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_AF_TRIGGER_ID, &item);
1142     if (ret == CAM_META_ITEM_NOT_FOUND) {
1143         status = changedMetadata_->addEntry(OHOS_CONTROL_AF_TRIGGER_ID, &triggerId, count);
1144     } else if (ret == CAM_META_SUCCESS) {
1145         status = changedMetadata_->updateEntry(OHOS_CONTROL_AF_TRIGGER_ID, &triggerId, count);
1146     }
1147 
1148     if (!status) {
1149         MEDIA_ERR_LOG("CaptureSession::SetFocusMode Failed to set trigger Id");
1150         return CameraErrorCode::SUCCESS;
1151     }
1152     return CameraErrorCode::SUCCESS;
1153 }
1154 
SetFocusMode(FocusMode focusMode)1155 int32_t CaptureSession::SetFocusMode(FocusMode focusMode)
1156 {
1157     CAMERA_SYNC_TRACE;
1158     if (!IsSessionCommited()) {
1159         MEDIA_ERR_LOG("CaptureSession::SetFocusMode Session is not Commited");
1160         return CameraErrorCode::SESSION_NOT_CONFIG;
1161     }
1162     if (changedMetadata_ == nullptr) {
1163         MEDIA_ERR_LOG("CaptureSession::SetFocusMode Need to call LockForControl() before setting camera properties");
1164         return CameraErrorCode::SUCCESS;
1165     }
1166     uint8_t focus = FOCUS_MODE_LOCKED;
1167     auto itr = fwToMetaFocusMode_.find(focusMode);
1168     if (itr == fwToMetaFocusMode_.end()) {
1169         MEDIA_ERR_LOG("CaptureSession::SetExposureMode Unknown exposure mode");
1170     } else {
1171         focus = itr->second;
1172     }
1173     bool status = false;
1174     int32_t ret;
1175     uint32_t count = 1;
1176     camera_metadata_item_t item;
1177 
1178     MEDIA_DEBUG_LOG("CaptureSession::SetFocusMode Focus mode: %{public}d", focusMode);
1179 
1180     ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_FOCUS_MODE, &item);
1181     if (ret == CAM_META_ITEM_NOT_FOUND) {
1182         status = changedMetadata_->addEntry(OHOS_CONTROL_FOCUS_MODE, &focus, count);
1183     } else if (ret == CAM_META_SUCCESS) {
1184         status = changedMetadata_->updateEntry(OHOS_CONTROL_FOCUS_MODE, &focus, count);
1185     }
1186 
1187     if (!status) {
1188         MEDIA_ERR_LOG("CaptureSession::SetFocusMode Failed to set focus mode");
1189     }
1190     return CameraErrorCode::SUCCESS;
1191 }
1192 
GetFocusMode()1193 FocusMode CaptureSession::GetFocusMode()
1194 {
1195     if (!IsSessionCommited()) {
1196         MEDIA_ERR_LOG("CaptureSession::GetFocusMode Session is not Commited");
1197         return FOCUS_MODE_MANUAL;
1198     }
1199     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1200         MEDIA_ERR_LOG("CaptureSession::GetFocusMode camera device is null");
1201         return FOCUS_MODE_MANUAL;
1202     }
1203     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1204     camera_metadata_item_t item;
1205     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_FOCUS_MODE, &item);
1206     if (ret != CAM_META_SUCCESS) {
1207         MEDIA_ERR_LOG("CaptureSession::GetFocusMode Failed with return code %{public}d", ret);
1208         return FOCUS_MODE_MANUAL;
1209     }
1210     auto itr = metaToFwFocusMode_.find(static_cast<camera_focus_mode_enum_t>(item.data.u8[0]));
1211     if (itr != metaToFwFocusMode_.end()) {
1212         return itr->second;
1213     }
1214     return FOCUS_MODE_MANUAL;
1215 }
1216 
GetFocusMode(FocusMode & focusMode)1217 int32_t CaptureSession::GetFocusMode(FocusMode &focusMode)
1218 {
1219     focusMode = FOCUS_MODE_MANUAL;
1220     if (!IsSessionCommited()) {
1221         MEDIA_ERR_LOG("CaptureSession::GetFocusMode Session is not Commited");
1222         return CameraErrorCode::SESSION_NOT_CONFIG;
1223     }
1224     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1225         MEDIA_ERR_LOG("CaptureSession::GetFocusMode camera device is null");
1226         return CameraErrorCode::SUCCESS;
1227     }
1228     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1229     camera_metadata_item_t item;
1230     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_FOCUS_MODE, &item);
1231     if (ret != CAM_META_SUCCESS) {
1232         MEDIA_ERR_LOG("CaptureSession::GetFocusMode Failed with return code %{public}d", ret);
1233         return CameraErrorCode::SUCCESS;
1234     }
1235     auto itr = metaToFwFocusMode_.find(static_cast<camera_focus_mode_enum_t>(item.data.u8[0]));
1236     if (itr != metaToFwFocusMode_.end()) {
1237         focusMode = itr->second;
1238         return CameraErrorCode::SUCCESS;
1239     }
1240     return CameraErrorCode::SUCCESS;
1241 }
1242 
SetFocusPoint(Point focusPoint)1243 int32_t CaptureSession::SetFocusPoint(Point focusPoint)
1244 {
1245     if (!IsSessionCommited()) {
1246         MEDIA_ERR_LOG("CaptureSession::SetFocusPoint Session is not Commited");
1247         return CameraErrorCode::SESSION_NOT_CONFIG;
1248     }
1249     if (changedMetadata_ == nullptr) {
1250         MEDIA_ERR_LOG("CaptureSession::SetFocusPoint Need to call LockForControl() before setting camera properties");
1251         return CameraErrorCode::SUCCESS;
1252     }
1253     Point unifyFocusPoint = CoordinateTransform(focusPoint);
1254     bool status = false;
1255     float FocusArea[2] = {unifyFocusPoint.x, unifyFocusPoint.y};
1256     camera_metadata_item_t item;
1257 
1258     int ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_AF_REGIONS, &item);
1259     if (ret == CAM_META_ITEM_NOT_FOUND) {
1260         status = changedMetadata_->addEntry(OHOS_CONTROL_AF_REGIONS, FocusArea,
1261             sizeof(FocusArea) / sizeof(FocusArea[0]));
1262     } else if (ret == CAM_META_SUCCESS) {
1263         status = changedMetadata_->updateEntry(OHOS_CONTROL_AF_REGIONS, FocusArea,
1264             sizeof(FocusArea) / sizeof(FocusArea[0]));
1265     }
1266 
1267     if (!status) {
1268         MEDIA_ERR_LOG("CaptureSession::SetFocusPoint Failed to set Focus Area");
1269     }
1270     return CameraErrorCode::SUCCESS;
1271 }
1272 
CoordinateTransform(Point point)1273 Point CaptureSession::CoordinateTransform(Point point)
1274 {
1275     MEDIA_DEBUG_LOG("CaptureSession::CoordinateTransform begin x: %{public}f, y: %{public}f", point.x, point.y);
1276     Point unifyPoint = point;
1277     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1278         MEDIA_ERR_LOG("CaptureSession::CoordinateTransform cameraInput is nullptr");
1279         return unifyPoint;
1280     }
1281     if (inputDevice_->GetCameraDeviceInfo()->GetPosition() == CAMERA_POSITION_FRONT) {
1282         unifyPoint.x = 1 - unifyPoint.x; // flip horizontally
1283     }
1284     MEDIA_DEBUG_LOG("CaptureSession::CoordinateTransform end x: %{public}f, y: %{public}f",
1285                     unifyPoint.x, unifyPoint.y);
1286     return unifyPoint;
1287 }
1288 
GetFocusPoint()1289 Point CaptureSession::GetFocusPoint()
1290 {
1291     Point focusPoint = {0, 0};
1292     if (!IsSessionCommited()) {
1293         MEDIA_ERR_LOG("CaptureSession::GetFocusPoint Session is not Commited");
1294         return focusPoint;
1295     }
1296     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1297         MEDIA_ERR_LOG("CaptureSession::GetFocusPoint camera device is null");
1298         return focusPoint;
1299     }
1300     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1301     camera_metadata_item_t item;
1302     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_AF_REGIONS, &item);
1303     if (ret != CAM_META_SUCCESS) {
1304         MEDIA_ERR_LOG("CaptureSession::GetFocusPoint Failed with return code %{public}d", ret);
1305         return focusPoint;
1306     }
1307     focusPoint.x = item.data.f[0];
1308     focusPoint.y = item.data.f[1];
1309     Point unifyFocusPoint = CoordinateTransform(focusPoint);
1310     return unifyFocusPoint;
1311 }
1312 
GetFocusPoint(Point & focusPoint)1313 int32_t CaptureSession::GetFocusPoint(Point &focusPoint)
1314 {
1315     focusPoint.x = 0;
1316     focusPoint.y = 0;
1317     if (!IsSessionCommited()) {
1318         MEDIA_ERR_LOG("CaptureSession::GetFocusPoint Session is not Commited");
1319         return CameraErrorCode::SESSION_NOT_CONFIG;
1320     }
1321     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1322         MEDIA_ERR_LOG("CaptureSession::GetFocusPoint camera device is null");
1323         return CameraErrorCode::SUCCESS;
1324     }
1325     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1326     camera_metadata_item_t item;
1327     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_AF_REGIONS, &item);
1328     if (ret != CAM_META_SUCCESS) {
1329         MEDIA_ERR_LOG("CaptureSession::GetFocusPoint Failed with return code %{public}d", ret);
1330         return CameraErrorCode::SUCCESS;
1331     }
1332     focusPoint.x = item.data.f[0];
1333     focusPoint.y = item.data.f[1];
1334     focusPoint = CoordinateTransform(focusPoint);
1335     return CameraErrorCode::SUCCESS;
1336 }
1337 
GetFocalLength()1338 float CaptureSession::GetFocalLength()
1339 {
1340     if (!IsSessionCommited()) {
1341         MEDIA_ERR_LOG("CaptureSession::GetFocalLength Session is not Commited");
1342         return 0;
1343     }
1344     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1345         MEDIA_ERR_LOG("CaptureSession::GetFocalLength camera device is null");
1346         return 0;
1347     }
1348     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1349     camera_metadata_item_t item;
1350     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FOCAL_LENGTH, &item);
1351     if (ret != CAM_META_SUCCESS) {
1352         MEDIA_ERR_LOG("CaptureSession::GetFocalLength Failed with return code %{public}d", ret);
1353         return 0;
1354     }
1355     return static_cast<float>(item.data.f[0]);
1356 }
1357 
GetFocalLength(float & focalLength)1358 int32_t CaptureSession::GetFocalLength(float &focalLength)
1359 {
1360     focalLength = 0;
1361     if (!IsSessionCommited()) {
1362         MEDIA_ERR_LOG("CaptureSession::GetFocalLength Session is not Commited");
1363         return CameraErrorCode::SESSION_NOT_CONFIG;
1364     }
1365     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1366         MEDIA_ERR_LOG("CaptureSession::GetFocalLength camera device is null");
1367         return CameraErrorCode::SUCCESS;
1368     }
1369     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1370     camera_metadata_item_t item;
1371     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FOCAL_LENGTH, &item);
1372     if (ret != CAM_META_SUCCESS) {
1373         MEDIA_ERR_LOG("CaptureSession::GetFocalLength Failed with return code %{public}d", ret);
1374         return CameraErrorCode::SUCCESS;
1375     }
1376     focalLength = static_cast<float>(item.data.f[0]);
1377     return CameraErrorCode::SUCCESS;
1378 }
1379 
ProcessAutoFocusUpdates(const std::shared_ptr<Camera::CameraMetadata> & result)1380 void CaptureSession::ProcessAutoFocusUpdates(const std::shared_ptr<Camera::CameraMetadata> &result)
1381 {
1382     camera_metadata_item_t item;
1383     common_metadata_header_t* metadata = result->get();
1384     int ret = Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_FOCUS_MODE, &item);
1385     if (ret == CAM_META_SUCCESS) {
1386         MEDIA_DEBUG_LOG("Focus mode: %{public}d", item.data.u8[0]);
1387     }
1388     ret = Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_FOCUS_STATE, &item);
1389     if (ret == CAM_META_SUCCESS) {
1390         MEDIA_INFO_LOG("Focus state: %{public}d", item.data.u8[0]);
1391         if (focusCallback_ != nullptr) {
1392             auto itr = metaToFwFocusState_.find(static_cast<camera_focus_state_t>(item.data.u8[0]));
1393             if (itr != metaToFwFocusState_.end()) {
1394                 focusCallback_->OnFocusState(itr->second);
1395             }
1396         }
1397     }
1398 }
1399 
GetSupportedFlashModes()1400 std::vector<FlashMode> CaptureSession::GetSupportedFlashModes()
1401 {
1402     std::vector<FlashMode> supportedFlashModes = {};
1403     if (!IsSessionCommited()) {
1404         MEDIA_ERR_LOG("CaptureSession::GetSupportedFlashModes Session is not Commited");
1405         return supportedFlashModes;
1406     }
1407     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1408         MEDIA_ERR_LOG("CaptureSession::GetSupportedFlashModes camera device is null");
1409         return supportedFlashModes;
1410     }
1411     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1412     camera_metadata_item_t item;
1413     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FLASH_MODES, &item);
1414     if (ret != CAM_META_SUCCESS) {
1415         MEDIA_ERR_LOG("CaptureSession::GetSupportedFlashModes Failed with return code %{public}d", ret);
1416         return supportedFlashModes;
1417     }
1418     for (uint32_t i = 0; i < item.count; i++) {
1419         auto itr = metaToFwFlashMode_.find(static_cast<camera_flash_mode_enum_t>(item.data.u8[i]));
1420         if (itr != metaToFwFlashMode_.end()) {
1421             supportedFlashModes.emplace_back(itr->second);
1422         }
1423     }
1424     return supportedFlashModes;
1425 }
1426 
GetSupportedFlashModes(std::vector<FlashMode> & supportedFlashModes)1427 int32_t CaptureSession::GetSupportedFlashModes(std::vector<FlashMode> &supportedFlashModes)
1428 {
1429     supportedFlashModes.clear();
1430     if (!IsSessionCommited()) {
1431         MEDIA_ERR_LOG("CaptureSession::GetSupportedFlashModes Session is not Commited");
1432         return CameraErrorCode::SESSION_NOT_CONFIG;
1433     }
1434     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1435         MEDIA_ERR_LOG("CaptureSession::GetSupportedFlashModes camera device is null");
1436         return CameraErrorCode::SUCCESS;
1437     }
1438     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1439     camera_metadata_item_t item;
1440     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FLASH_MODES, &item);
1441     if (ret != CAM_META_SUCCESS) {
1442         MEDIA_ERR_LOG("CaptureSession::GetSupportedFlashModes Failed with return code %{public}d", ret);
1443         return CameraErrorCode::SUCCESS;
1444     }
1445     for (uint32_t i = 0; i < item.count; i++) {
1446         auto itr = metaToFwFlashMode_.find(static_cast<camera_flash_mode_enum_t>(item.data.u8[i]));
1447         if (itr != metaToFwFlashMode_.end()) {
1448             supportedFlashModes.emplace_back(itr->second);
1449         }
1450     }
1451     return CameraErrorCode::SUCCESS;
1452 }
1453 
GetFlashMode()1454 FlashMode CaptureSession::GetFlashMode()
1455 {
1456     if (!IsSessionCommited()) {
1457         MEDIA_ERR_LOG("CaptureSession::GetFlashMode Session is not Commited");
1458         return FLASH_MODE_CLOSE;
1459     }
1460     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1461         MEDIA_ERR_LOG("CaptureSession::GetFlashMode camera device is null");
1462         return FLASH_MODE_CLOSE;
1463     }
1464     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1465     camera_metadata_item_t item;
1466     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_FLASH_MODE, &item);
1467     if (ret != CAM_META_SUCCESS) {
1468         MEDIA_ERR_LOG("CaptureSession::GetFlashMode Failed with return code %{public}d", ret);
1469         return FLASH_MODE_CLOSE;
1470     }
1471     auto itr = metaToFwFlashMode_.find(static_cast<camera_flash_mode_enum_t>(item.data.u8[0]));
1472     if (itr != metaToFwFlashMode_.end()) {
1473         return itr->second;
1474     }
1475 
1476     return FLASH_MODE_CLOSE;
1477 }
1478 
GetFlashMode(FlashMode & flashMode)1479 int32_t CaptureSession::GetFlashMode(FlashMode &flashMode)
1480 {
1481     flashMode = FLASH_MODE_CLOSE;
1482     if (!IsSessionCommited()) {
1483         MEDIA_ERR_LOG("CaptureSession::GetFlashMode Session is not Commited");
1484         return CameraErrorCode::SESSION_NOT_CONFIG;
1485     }
1486     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1487         MEDIA_ERR_LOG("CaptureSession::GetFlashMode camera device is null");
1488         return CameraErrorCode::SUCCESS;
1489     }
1490     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1491     camera_metadata_item_t item;
1492     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_FLASH_MODE, &item);
1493     if (ret != CAM_META_SUCCESS) {
1494         MEDIA_ERR_LOG("CaptureSession::GetFlashMode Failed with return code %{public}d", ret);
1495         return CameraErrorCode::SUCCESS;
1496     }
1497     auto itr = metaToFwFlashMode_.find(static_cast<camera_flash_mode_enum_t>(item.data.u8[0]));
1498     if (itr != metaToFwFlashMode_.end()) {
1499         flashMode = itr->second;
1500         return CameraErrorCode::SUCCESS;
1501     }
1502 
1503     return CameraErrorCode::SUCCESS;
1504 }
1505 
SetFlashMode(FlashMode flashMode)1506 int32_t CaptureSession::SetFlashMode(FlashMode flashMode)
1507 {
1508     CAMERA_SYNC_TRACE;
1509     if (!IsSessionCommited()) {
1510         MEDIA_ERR_LOG("CaptureSession::SetFlashMode Session is not Commited");
1511         return CameraErrorCode::SESSION_NOT_CONFIG;
1512     }
1513     if (changedMetadata_ == nullptr) {
1514         MEDIA_ERR_LOG("CaptureSession::SetFlashMode Need to call LockForControl() before setting camera properties");
1515         return CameraErrorCode::SUCCESS;
1516     }
1517     uint8_t flash = fwToMetaFlashMode_.at(FLASH_MODE_CLOSE);
1518     auto itr = fwToMetaFlashMode_.find(flashMode);
1519     if (itr == fwToMetaFlashMode_.end()) {
1520         MEDIA_ERR_LOG("CaptureSession::SetExposureMode Unknown exposure mode");
1521     } else {
1522         flash = itr->second;
1523     }
1524 
1525     bool status = false;
1526     uint32_t count = 1;
1527     camera_metadata_item_t item;
1528     int ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_FLASH_MODE, &item);
1529     if (ret == CAM_META_ITEM_NOT_FOUND) {
1530         status = changedMetadata_->addEntry(OHOS_CONTROL_FLASH_MODE, &flash, count);
1531     } else if (ret == CAM_META_SUCCESS) {
1532         status = changedMetadata_->updateEntry(OHOS_CONTROL_FLASH_MODE, &flash, count);
1533     }
1534 
1535     if (!status) {
1536         MEDIA_ERR_LOG("CaptureSession::SetFlashMode Failed to set flash mode");
1537         return CameraErrorCode::SUCCESS;
1538     }
1539 
1540     if (flashMode == FLASH_MODE_CLOSE) {
1541         POWERMGR_SYSEVENT_FLASH_OFF();
1542     } else {
1543         POWERMGR_SYSEVENT_FLASH_ON();
1544     }
1545     return CameraErrorCode::SUCCESS;
1546 }
1547 
IsFlashModeSupported(FlashMode flashMode)1548 bool CaptureSession::IsFlashModeSupported(FlashMode flashMode)
1549 {
1550     std::vector<FlashMode> vecSupportedFlashModeList;
1551     vecSupportedFlashModeList = this->GetSupportedFlashModes();
1552     if (find(vecSupportedFlashModeList.begin(), vecSupportedFlashModeList.end(), flashMode) !=
1553         vecSupportedFlashModeList.end()) {
1554         return true;
1555     }
1556 
1557     return false;
1558 }
1559 
IsFlashModeSupported(FlashMode flashMode,bool & isSupported)1560 int32_t CaptureSession::IsFlashModeSupported(FlashMode flashMode, bool &isSupported)
1561 {
1562     if (!IsSessionCommited()) {
1563         MEDIA_ERR_LOG("CaptureSession::IsFlashModeSupported Session is not Commited");
1564         return CameraErrorCode::SESSION_NOT_CONFIG;
1565     }
1566     std::vector<FlashMode> vecSupportedFlashModeList;
1567     vecSupportedFlashModeList = this->GetSupportedFlashModes();
1568     if (find(vecSupportedFlashModeList.begin(), vecSupportedFlashModeList.end(), flashMode) !=
1569         vecSupportedFlashModeList.end()) {
1570         isSupported = true;
1571         return CameraErrorCode::SUCCESS;
1572     }
1573     isSupported = false;
1574     return CameraErrorCode::SUCCESS;
1575 }
1576 
HasFlash()1577 bool CaptureSession::HasFlash()
1578 {
1579     std::vector<FlashMode> vecSupportedFlashModeList;
1580     vecSupportedFlashModeList = this->GetSupportedFlashModes();
1581     if (vecSupportedFlashModeList.empty()) {
1582         return false;
1583     }
1584     return true;
1585 }
1586 
HasFlash(bool & hasFlash)1587 int32_t CaptureSession::HasFlash(bool &hasFlash)
1588 {
1589     if (!IsSessionCommited()) {
1590         MEDIA_ERR_LOG("CaptureSession::HasFlash Session is not Commited");
1591         return CameraErrorCode::SESSION_NOT_CONFIG;
1592     }
1593     std::vector<FlashMode> vecSupportedFlashModeList;
1594     vecSupportedFlashModeList = this->GetSupportedFlashModes();
1595     if (vecSupportedFlashModeList.empty()) {
1596         hasFlash = false;
1597         return CameraErrorCode::SUCCESS;
1598     }
1599     hasFlash = true;
1600     return CameraErrorCode::SUCCESS;
1601 }
1602 
GetZoomRatioRange()1603 std::vector<float> CaptureSession::GetZoomRatioRange()
1604 {
1605     if (!IsSessionCommited()) {
1606         MEDIA_ERR_LOG("CaptureSession::GetZoomRatioRange Session is not Commited");
1607         return {};
1608     }
1609     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1610         MEDIA_ERR_LOG("CaptureSession::GetZoomRatioRange camera device is null");
1611         return {};
1612     }
1613     return inputDevice_->GetCameraDeviceInfo()->GetZoomRatioRange();
1614 }
1615 
GetZoomRatioRange(std::vector<float> & zoomRatioRange)1616 int32_t CaptureSession::GetZoomRatioRange(std::vector<float> &zoomRatioRange)
1617 {
1618     zoomRatioRange.clear();
1619     if (!IsSessionCommited()) {
1620         MEDIA_ERR_LOG("CaptureSession::GetZoomRatioRange Session is not Commited");
1621         return CameraErrorCode::SESSION_NOT_CONFIG;
1622     }
1623     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1624         MEDIA_ERR_LOG("CaptureSession::GetZoomRatioRange camera device is null");
1625         return CameraErrorCode::SUCCESS;
1626     }
1627     zoomRatioRange = inputDevice_->GetCameraDeviceInfo()->GetZoomRatioRange();
1628     return CameraErrorCode::SUCCESS;
1629 }
1630 
GetZoomRatio()1631 float CaptureSession::GetZoomRatio()
1632 {
1633     if (!IsSessionCommited()) {
1634         MEDIA_ERR_LOG("CaptureSession::GetZoomRatio Session is not Commited");
1635         return 0;
1636     }
1637     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1638         MEDIA_ERR_LOG("CaptureSession::GetZoomRatio camera device is null");
1639         return 0;
1640     }
1641     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1642     camera_metadata_item_t item;
1643     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_ZOOM_RATIO, &item);
1644     if (ret != CAM_META_SUCCESS) {
1645         MEDIA_ERR_LOG("CaptureSession::GetZoomRatio Failed with return code %{public}d", ret);
1646         return 0;
1647     }
1648     return static_cast<float>(item.data.f[0]);
1649 }
1650 
GetZoomRatio(float & zoomRatio)1651 int32_t CaptureSession::GetZoomRatio(float &zoomRatio)
1652 {
1653     zoomRatio = 0;
1654     if (!IsSessionCommited()) {
1655         MEDIA_ERR_LOG("CaptureSession::GetZoomRatio Session is not Commited");
1656         return CameraErrorCode::SESSION_NOT_CONFIG;
1657     }
1658     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1659         MEDIA_ERR_LOG("CaptureSession::GetZoomRatio camera device is null");
1660         return CameraErrorCode::SUCCESS;
1661     }
1662     std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1663     camera_metadata_item_t item;
1664     int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_ZOOM_RATIO, &item);
1665     if (ret != CAM_META_SUCCESS) {
1666         MEDIA_ERR_LOG("CaptureSession::GetZoomRatio Failed with return code %{public}d", ret);
1667         return CameraErrorCode::SUCCESS;
1668     }
1669     zoomRatio = static_cast<float>(item.data.f[0]);
1670     return CameraErrorCode::SUCCESS;
1671 }
1672 
SetCropRegion(float zoomRatio)1673 int32_t CaptureSession::SetCropRegion(float zoomRatio)
1674 {
1675     bool status = false;
1676     int32_t ret;
1677     int32_t leftIndex = 0;
1678     int32_t topIndex = 1;
1679     int32_t rightIndex = 2;
1680     int32_t bottomIndex = 3;
1681     int32_t factor = 2;
1682     int32_t sensorRight;
1683     int32_t sensorBottom;
1684     const uint32_t arrayCount = 4;
1685     int32_t cropRegion[arrayCount] = {};
1686     camera_metadata_item_t item;
1687     if (!IsSessionCommited()) {
1688         MEDIA_ERR_LOG("CaptureSession::SetCropRegion Session is not Commited");
1689         return CameraErrorCode::SESSION_NOT_CONFIG;
1690     }
1691     if (zoomRatio == 0) {
1692         MEDIA_ERR_LOG("CaptureSession::SetCropRegion Invalid zoom ratio");
1693         return CameraErrorCode::SUCCESS;
1694     }
1695     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1696         MEDIA_ERR_LOG("CaptureSession::SetCropRegion camera device is null");
1697         return CameraErrorCode::SUCCESS;
1698     }
1699     ret = Camera::FindCameraMetadataItem(
1700         inputDevice_->GetCameraDeviceInfo()->GetMetadata()->get(), OHOS_SENSOR_INFO_ACTIVE_ARRAY_SIZE, &item);
1701     if (ret != CAM_META_SUCCESS) {
1702         MEDIA_ERR_LOG("CaptureSession::SetCropRegion Failed to get sensor active array size, return code %{public}d",
1703                       ret);
1704         return CameraErrorCode::SUCCESS;
1705     }
1706     if (item.count != arrayCount) {
1707         MEDIA_ERR_LOG("CaptureSession::SetCropRegion Invalid sensor active array size count: %{public}u", item.count);
1708         return CameraErrorCode::SUCCESS;
1709     }
1710     MEDIA_DEBUG_LOG("CaptureSession::SetCropRegion Sensor active array left: %{public}d, top: %{public}d, "
1711                     "right: %{public}d, bottom: %{public}d", item.data.i32[leftIndex], item.data.i32[topIndex],
1712                     item.data.i32[rightIndex], item.data.i32[bottomIndex]);
1713     sensorRight = item.data.i32[rightIndex];
1714     sensorBottom = item.data.i32[bottomIndex];
1715     cropRegion[leftIndex] = (sensorRight - (sensorRight / zoomRatio)) / factor;
1716     cropRegion[topIndex] = (sensorBottom - (sensorBottom / zoomRatio)) / factor;
1717     cropRegion[rightIndex] = cropRegion[leftIndex] + (sensorRight / zoomRatio);
1718     cropRegion[bottomIndex] = cropRegion[topIndex] + (sensorBottom / zoomRatio);
1719     MEDIA_DEBUG_LOG("CaptureSession::SetCropRegion Crop region left: %{public}d, top: %{public}d, "
1720                     "right: %{public}d, bottom: %{public}d", cropRegion[leftIndex], cropRegion[topIndex],
1721                     cropRegion[rightIndex], cropRegion[bottomIndex]);
1722     ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_ZOOM_CROP_REGION, &item);
1723     if (ret == CAM_META_ITEM_NOT_FOUND) {
1724         status = changedMetadata_->addEntry(OHOS_CONTROL_ZOOM_CROP_REGION, cropRegion, arrayCount);
1725     } else if (ret == CAM_META_SUCCESS) {
1726         status = changedMetadata_->updateEntry(OHOS_CONTROL_ZOOM_CROP_REGION, cropRegion, arrayCount);
1727     }
1728     if (!status) {
1729         MEDIA_ERR_LOG("CaptureSession::SetCropRegion Failed to set zoom crop region");
1730         return CameraErrorCode::SUCCESS;
1731     }
1732     return CameraErrorCode::SUCCESS;
1733 }
1734 
SetZoomRatio(float zoomRatio)1735 int32_t CaptureSession::SetZoomRatio(float zoomRatio)
1736 {
1737     CAMERA_SYNC_TRACE;
1738     if (!IsSessionCommited()) {
1739         MEDIA_ERR_LOG("CaptureSession::SetZoomRatio Session is not Commited");
1740         return CameraErrorCode::SESSION_NOT_CONFIG;
1741     }
1742     if (changedMetadata_ == nullptr) {
1743         MEDIA_ERR_LOG("CaptureSession::SetZoomRatio Need to call LockForControl() before setting camera properties");
1744         return CameraErrorCode::SUCCESS;
1745     }
1746 
1747     bool status = false;
1748     int32_t ret;
1749     int32_t minIndex = 0;
1750     int32_t maxIndex = 1;
1751     int32_t count = 1;
1752     camera_metadata_item_t item;
1753     MEDIA_DEBUG_LOG("CaptureSession::SetZoomRatio Zoom ratio: %{public}f", zoomRatio);
1754     if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1755         MEDIA_ERR_LOG("CaptureSession::SetZoomRatio camera device is null");
1756         return CameraErrorCode::SUCCESS;
1757     }
1758     std::vector<float> zoomRange = inputDevice_->GetCameraDeviceInfo()->GetZoomRatioRange();
1759     if (zoomRange.empty()) {
1760         MEDIA_ERR_LOG("CaptureSession::SetZoomRatio Zoom range is empty");
1761         return CameraErrorCode::SUCCESS;
1762     }
1763     if (zoomRatio < zoomRange[minIndex]) {
1764         MEDIA_DEBUG_LOG("CaptureSession::SetZoomRatio Zoom ratio: %{public}f is lesser than minimum zoom: %{public}f",
1765                         zoomRatio, zoomRange[minIndex]);
1766         zoomRatio = zoomRange[minIndex];
1767     } else if (zoomRatio > zoomRange[maxIndex]) {
1768         MEDIA_DEBUG_LOG("CaptureSession::SetZoomRatio Zoom ratio: %{public}f is greater than maximum zoom: %{public}f",
1769                         zoomRatio, zoomRange[maxIndex]);
1770         zoomRatio = zoomRange[maxIndex];
1771     }
1772 
1773     if (zoomRatio == 0) {
1774         MEDIA_ERR_LOG("CaptureSession::SetZoomRatio Invalid zoom ratio");
1775         return CameraErrorCode::SUCCESS;
1776     }
1777 
1778     ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_ZOOM_RATIO, &item);
1779     if (ret == CAM_META_ITEM_NOT_FOUND) {
1780         status = changedMetadata_->addEntry(OHOS_CONTROL_ZOOM_RATIO, &zoomRatio, count);
1781     } else if (ret == CAM_META_SUCCESS) {
1782         status = changedMetadata_->updateEntry(OHOS_CONTROL_ZOOM_RATIO, &zoomRatio, count);
1783     }
1784 
1785     if (!status) {
1786         MEDIA_ERR_LOG("CaptureSession::SetZoomRatio Failed to set zoom mode");
1787     }
1788     return CameraErrorCode::SUCCESS;
1789 }
1790 
SetCaptureMetadataObjectTypes(std::set<camera_face_detect_mode_t> metadataObjectTypes)1791 void CaptureSession::SetCaptureMetadataObjectTypes(std::set<camera_face_detect_mode_t> metadataObjectTypes)
1792 {
1793     if (inputDevice_ == nullptr) {
1794         MEDIA_ERR_LOG("SetCaptureMetadataObjectTypes: inputDevice is null");
1795         return;
1796     }
1797     uint32_t count = 0;
1798     uint8_t objectTypes[metadataObjectTypes.size()];
1799     for (const auto &type : metadataObjectTypes) {
1800         objectTypes[count++] = type;
1801     }
1802     this->LockForControl();
1803     if (!this->changedMetadata_->addEntry(OHOS_STATISTICS_FACE_DETECT_SWITCH, objectTypes, count)) {
1804         MEDIA_ERR_LOG("SetCaptureMetadataObjectTypes: Failed to add detect object types to changed metadata");
1805     }
1806     this->UnlockForControl();
1807 }
1808 
SetFrameRateRange(const std::vector<int32_t> & frameRateRange)1809 void CaptureSession::SetFrameRateRange(const std::vector<int32_t>& frameRateRange)
1810 {
1811     if (!IsSessionCommited()) {
1812         MEDIA_ERR_LOG("UpdateConfigSetting: inputDevice is null");
1813         return;
1814     }
1815 
1816     std::vector<int32_t> videoFrameRateRange = frameRateRange;
1817     this->LockForControl();
1818     if (!this->changedMetadata_->addEntry(OHOS_CONTROL_FPS_RANGES,
1819         videoFrameRateRange.data(), videoFrameRateRange.size())) {
1820         MEDIA_ERR_LOG("Failed to SetFrameRateRange");
1821     }
1822     this->UnlockForControl();
1823 }
1824 
IsSessionConfiged()1825 bool CaptureSession::IsSessionConfiged()
1826 {
1827     bool isSessionConfiged = false;
1828     if (captureSession_) {
1829         CaptureSessionState currentState;
1830         captureSession_->GetSessionState(currentState);
1831         isSessionConfiged = (currentState == CaptureSessionState::SESSION_CONFIG_INPROGRESS);
1832     }
1833     return isSessionConfiged;
1834 }
1835 
IsSessionCommited()1836 bool CaptureSession::IsSessionCommited()
1837 {
1838     bool isCommitConfig = false;
1839     if (captureSession_) {
1840         CaptureSessionState currentState;
1841         captureSession_->GetSessionState(currentState);
1842         isCommitConfig = (currentState == CaptureSessionState::SESSION_CONFIG_COMMITTED);
1843     }
1844     return isCommitConfig;
1845 }
1846 } // CameraStandard
1847 } // OHOS
1848