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 CaptureSession* captureSession_ = nullptr;
CaptureSessionCallback()105 CaptureSessionCallback() : captureSession_(nullptr) {
106 }
107
CaptureSessionCallback(CaptureSession * captureSession)108 explicit CaptureSessionCallback(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 exposureVerifyPoint = VerifyFocusCorrectness(exposurePoint);
809 Point unifyExposurePoint = CoordinateTransform(exposureVerifyPoint);
810 bool status = false;
811 float exposureArea[2] = {unifyExposurePoint.x, unifyExposurePoint.y};
812 camera_metadata_item_t item;
813
814 int ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_AE_REGIONS, &item);
815 if (ret == CAM_META_ITEM_NOT_FOUND) {
816 status = changedMetadata_->addEntry(OHOS_CONTROL_AE_REGIONS, exposureArea,
817 sizeof(exposureArea) / sizeof(exposureArea[0]));
818 } else if (ret == CAM_META_SUCCESS) {
819 status = changedMetadata_->updateEntry(OHOS_CONTROL_AE_REGIONS, exposureArea,
820 sizeof(exposureArea) / sizeof(exposureArea[0]));
821 }
822
823 if (!status) {
824 MEDIA_ERR_LOG("CaptureSession::SetExposurePoint Failed to set exposure Area");
825 }
826 return CameraErrorCode::SUCCESS;
827 }
828
GetMeteringPoint()829 Point CaptureSession::GetMeteringPoint()
830 {
831 Point exposurePoint = {0, 0};
832 if (!IsSessionCommited()) {
833 MEDIA_ERR_LOG("CaptureSession::GetMeteringPoint Session is not Commited");
834 return exposurePoint;
835 }
836 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
837 MEDIA_ERR_LOG("CaptureSession::GetMeteringPoint camera device is null");
838 return exposurePoint;
839 }
840 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
841 camera_metadata_item_t item;
842 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_AE_REGIONS, &item);
843 if (ret != CAM_META_SUCCESS) {
844 MEDIA_ERR_LOG("CaptureSession::GetExposurePoint Failed with return code %{public}d", ret);
845 return exposurePoint;
846 }
847 exposurePoint.x = item.data.f[0];
848 exposurePoint.y = item.data.f[1];
849 Point unifyExposurePoint = CoordinateTransform(exposurePoint);
850 return unifyExposurePoint;
851 }
852
GetMeteringPoint(Point & exposurePoint)853 int32_t CaptureSession::GetMeteringPoint(Point &exposurePoint)
854 {
855 exposurePoint.x = 0;
856 exposurePoint.y = 0;
857 if (!IsSessionCommited()) {
858 MEDIA_ERR_LOG("CaptureSession::GetMeteringPoint Session is not Commited");
859 return CameraErrorCode::SESSION_NOT_CONFIG;
860 }
861 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
862 MEDIA_ERR_LOG("CaptureSession::GetMeteringPoint camera device is null");
863 return CameraErrorCode::SUCCESS;
864 }
865 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
866 camera_metadata_item_t item;
867 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_AE_REGIONS, &item);
868 if (ret != CAM_META_SUCCESS) {
869 MEDIA_ERR_LOG("CaptureSession::GetExposurePoint Failed with return code %{public}d", ret);
870 return CameraErrorCode::SUCCESS;
871 }
872 exposurePoint.x = item.data.f[0];
873 exposurePoint.y = item.data.f[1];
874 exposurePoint = CoordinateTransform(exposurePoint);
875 return CameraErrorCode::SUCCESS;
876 }
877
GetExposureBiasRange()878 std::vector<int32_t> CaptureSession::GetExposureBiasRange()
879 {
880 if (!IsSessionCommited()) {
881 MEDIA_ERR_LOG("CaptureSession::GetExposureBiasRange Session is not Commited");
882 return {};
883 }
884 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
885 MEDIA_ERR_LOG("CaptureSession::GetExposureBiasRange camera device is null");
886 return {};
887 }
888 return inputDevice_->GetCameraDeviceInfo()->GetExposureBiasRange();
889 }
890
GetExposureBiasRange(std::vector<int32_t> & exposureBiasRange)891 int32_t CaptureSession::GetExposureBiasRange(std::vector<int32_t> &exposureBiasRange)
892 {
893 if (!IsSessionCommited()) {
894 MEDIA_ERR_LOG("CaptureSession::GetExposureBiasRange Session is not Commited");
895 return CameraErrorCode::SESSION_NOT_CONFIG;
896 }
897 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
898 MEDIA_ERR_LOG("CaptureSession::GetExposureBiasRange camera device is null");
899 return CameraErrorCode::SUCCESS;
900 }
901 exposureBiasRange = inputDevice_->GetCameraDeviceInfo()->GetExposureBiasRange();
902 return CameraErrorCode::SUCCESS;
903 }
904
905
SetExposureBias(int32_t exposureValue)906 int32_t CaptureSession::SetExposureBias(int32_t exposureValue)
907 {
908 if (!IsSessionCommited()) {
909 MEDIA_ERR_LOG("CaptureSession::SetExposureBias Session is not Commited");
910 return CameraErrorCode::SESSION_NOT_CONFIG;
911 }
912 if (changedMetadata_ == nullptr) {
913 MEDIA_ERR_LOG("CaptureSession::SetExposureValue Need to call LockForControl() "
914 "before setting camera properties");
915 return CameraErrorCode::SUCCESS;
916 }
917 bool status = false;
918 int32_t ret;
919 int32_t minIndex = 0;
920 int32_t maxIndex = 1;
921 int32_t count = 1;
922 camera_metadata_item_t item;
923 MEDIA_DEBUG_LOG("CaptureSession::SetExposureValue exposure compensation: %{public}d", exposureValue);
924 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
925 MEDIA_ERR_LOG("CaptureSession::SetExposureBias camera device is null");
926 return CameraErrorCode::SUCCESS;
927 }
928 std::vector<int32_t> biasRange = inputDevice_->GetCameraDeviceInfo()->GetExposureBiasRange();
929 if (biasRange.empty()) {
930 MEDIA_ERR_LOG("CaptureSession::SetExposureValue Bias range is empty");
931 return CameraErrorCode::SUCCESS;
932 }
933 if (exposureValue < biasRange[minIndex]) {
934 MEDIA_DEBUG_LOG("CaptureSession::SetExposureValue bias value:"
935 "%{public}d is lesser than minimum bias: %{public}d", exposureValue, biasRange[minIndex]);
936 exposureValue = biasRange[minIndex];
937 } else if (exposureValue > biasRange[maxIndex]) {
938 MEDIA_DEBUG_LOG("CaptureSession::SetExposureValue bias value: "
939 "%{public}d is greater than maximum bias: %{public}d", exposureValue, biasRange[maxIndex]);
940 exposureValue = biasRange[maxIndex];
941 }
942 if (exposureValue == 0) {
943 MEDIA_ERR_LOG("CaptureSession::SetExposureValue Invalid exposure compensation value");
944 return CameraErrorCode::SUCCESS;
945 }
946 ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &item);
947 if (ret == CAM_META_ITEM_NOT_FOUND) {
948 status = changedMetadata_->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &exposureValue, count);
949 } else if (ret == CAM_META_SUCCESS) {
950 status = changedMetadata_->updateEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &exposureValue, count);
951 }
952 if (!status) {
953 MEDIA_ERR_LOG("CaptureSession::SetExposureValue Failed to set exposure compensation");
954 }
955 return CameraErrorCode::SUCCESS;
956 }
957
GetExposureValue()958 int32_t CaptureSession::GetExposureValue()
959 {
960 if (!IsSessionCommited()) {
961 MEDIA_ERR_LOG("CaptureSession::GetExposureValue Session is not Commited");
962 return 0;
963 }
964 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
965 MEDIA_ERR_LOG("CaptureSession::GetExposureValue camera device is null");
966 return 0;
967 }
968 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
969 camera_metadata_item_t item;
970 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &item);
971 if (ret != CAM_META_SUCCESS) {
972 MEDIA_ERR_LOG("CaptureSession::GetExposureValue Failed with return code %{public}d", ret);
973 return 0;
974 }
975 return static_cast<int32_t>(item.data.i32[0]);
976 }
977
GetExposureValue(int32_t & exposureValue)978 int32_t CaptureSession::GetExposureValue(int32_t &exposureValue)
979 {
980 if (!IsSessionCommited()) {
981 MEDIA_ERR_LOG("CaptureSession::GetExposureValue Session is not Commited");
982 return CameraErrorCode::SESSION_NOT_CONFIG;
983 }
984 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
985 MEDIA_ERR_LOG("CaptureSession::GetExposureValue camera device is null");
986 return CameraErrorCode::SUCCESS;
987 }
988 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
989 camera_metadata_item_t item;
990 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &item);
991 if (ret != CAM_META_SUCCESS) {
992 MEDIA_ERR_LOG("CaptureSession::GetExposureValue Failed with return code %{public}d", ret);
993 return CameraErrorCode::SUCCESS;
994 }
995 exposureValue = static_cast<int32_t>(item.data.i32[0]);
996 return CameraErrorCode::SUCCESS;
997 }
998
SetExposureCallback(std::shared_ptr<ExposureCallback> exposureCallback)999 void CaptureSession::SetExposureCallback(std::shared_ptr<ExposureCallback> exposureCallback)
1000 {
1001 exposureCallback_ = exposureCallback;
1002 }
1003
ProcessAutoExposureUpdates(const std::shared_ptr<Camera::CameraMetadata> & result)1004 void CaptureSession::ProcessAutoExposureUpdates(const std::shared_ptr<Camera::CameraMetadata> &result)
1005 {
1006 camera_metadata_item_t item;
1007 common_metadata_header_t* metadata = result->get();
1008
1009 int ret = Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_EXPOSURE_MODE, &item);
1010 if (ret == CAM_META_SUCCESS) {
1011 MEDIA_DEBUG_LOG("exposure mode: %{public}d", item.data.u8[0]);
1012 }
1013
1014 ret = Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_EXPOSURE_STATE, &item);
1015 if (ret == CAM_META_SUCCESS) {
1016 MEDIA_INFO_LOG("Exposure state: %{public}d", item.data.u8[0]);
1017 if (exposureCallback_ != nullptr) {
1018 auto itr = metaToFwExposureState_.find(static_cast<camera_exposure_state_t>(item.data.u8[0]));
1019 if (itr != metaToFwExposureState_.end()) {
1020 exposureCallback_->OnExposureState(itr->second);
1021 }
1022 }
1023 }
1024 }
1025
GetSupportedFocusModes()1026 std::vector<FocusMode> CaptureSession::GetSupportedFocusModes()
1027 {
1028 std::vector<FocusMode> supportedFocusModes = {};
1029 if (!IsSessionCommited()) {
1030 MEDIA_ERR_LOG("CaptureSession::SetExposureBias Session is not Commited");
1031 return supportedFocusModes;
1032 }
1033 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1034 MEDIA_ERR_LOG("CaptureSession::GetSupportedFocusModes camera device is null");
1035 return supportedFocusModes;
1036 }
1037 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1038 camera_metadata_item_t item;
1039 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FOCUS_MODES, &item);
1040 if (ret != CAM_META_SUCCESS) {
1041 MEDIA_ERR_LOG("CaptureSession::GetSupportedFocusModes Failed with return code %{public}d", ret);
1042 return supportedFocusModes;
1043 }
1044 for (uint32_t i = 0; i < item.count; i++) {
1045 auto itr = metaToFwFocusMode_.find(static_cast<camera_focus_mode_enum_t>(item.data.u8[i]));
1046 if (itr != metaToFwFocusMode_.end()) {
1047 supportedFocusModes.emplace_back(itr->second);
1048 }
1049 }
1050 return supportedFocusModes;
1051 }
1052
GetSupportedFocusModes(std::vector<FocusMode> & supportedFocusModes)1053 int32_t CaptureSession::GetSupportedFocusModes(std::vector<FocusMode> &supportedFocusModes)
1054 {
1055 supportedFocusModes.clear();
1056 if (!IsSessionCommited()) {
1057 MEDIA_ERR_LOG("CaptureSession::SetExposureBias Session is not Commited");
1058 return CameraErrorCode::SESSION_NOT_CONFIG;
1059 }
1060 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1061 MEDIA_ERR_LOG("CaptureSession::GetSupportedFocusModes camera device is null");
1062 return CameraErrorCode::SUCCESS;
1063 }
1064 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1065 camera_metadata_item_t item;
1066 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FOCUS_MODES, &item);
1067 if (ret != CAM_META_SUCCESS) {
1068 MEDIA_ERR_LOG("CaptureSession::GetSupportedFocusModes Failed with return code %{public}d", ret);
1069 return CameraErrorCode::SUCCESS;
1070 }
1071 for (uint32_t i = 0; i < item.count; i++) {
1072 auto itr = metaToFwFocusMode_.find(static_cast<camera_focus_mode_enum_t>(item.data.u8[i]));
1073 if (itr != metaToFwFocusMode_.end()) {
1074 supportedFocusModes.emplace_back(itr->second);
1075 return CameraErrorCode::SUCCESS;
1076 }
1077 }
1078 return CameraErrorCode::SUCCESS;
1079 }
1080
SetFocusCallback(std::shared_ptr<FocusCallback> focusCallback)1081 void CaptureSession::SetFocusCallback(std::shared_ptr<FocusCallback> focusCallback)
1082 {
1083 focusCallback_ = focusCallback;
1084 return;
1085 }
1086
IsFocusModeSupported(FocusMode focusMode)1087 bool CaptureSession::IsFocusModeSupported(FocusMode focusMode)
1088 {
1089 std::vector<FocusMode> vecSupportedFocusModeList;
1090 vecSupportedFocusModeList = this->GetSupportedFocusModes();
1091 if (find(vecSupportedFocusModeList.begin(), vecSupportedFocusModeList.end(),
1092 focusMode) != vecSupportedFocusModeList.end()) {
1093 return true;
1094 }
1095
1096 return false;
1097 }
1098
IsFocusModeSupported(FocusMode focusMode,bool & isSupported)1099 int32_t CaptureSession::IsFocusModeSupported(FocusMode focusMode, bool &isSupported)
1100 {
1101 if (!IsSessionCommited()) {
1102 MEDIA_ERR_LOG("CaptureSession::SetExposureBias Session is not Commited");
1103 return CameraErrorCode::SESSION_NOT_CONFIG;
1104 }
1105 std::vector<FocusMode> vecSupportedFocusModeList;
1106 vecSupportedFocusModeList = this->GetSupportedFocusModes();
1107 if (find(vecSupportedFocusModeList.begin(), vecSupportedFocusModeList.end(),
1108 focusMode) != vecSupportedFocusModeList.end()) {
1109 isSupported = true;
1110 return CameraErrorCode::SUCCESS;
1111 }
1112 isSupported = false;
1113 return CameraErrorCode::SUCCESS;
1114 }
1115
StartFocus(FocusMode focusMode)1116 int32_t CaptureSession::StartFocus(FocusMode focusMode)
1117 {
1118 bool status = false;
1119 int32_t ret;
1120 static int32_t triggerId = 0;
1121 uint32_t count = 1;
1122 uint8_t trigger = OHOS_CAMERA_AF_TRIGGER_START;
1123 camera_metadata_item_t item;
1124
1125 if (focusMode == FOCUS_MODE_MANUAL) {
1126 return CameraErrorCode::SUCCESS;
1127 }
1128
1129 ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_AF_TRIGGER, &item);
1130 if (ret == CAM_META_ITEM_NOT_FOUND) {
1131 status = changedMetadata_->addEntry(OHOS_CONTROL_AF_TRIGGER, &trigger, count);
1132 } else if (ret == CAM_META_SUCCESS) {
1133 status = changedMetadata_->updateEntry(OHOS_CONTROL_AF_TRIGGER, &trigger, count);
1134 }
1135
1136 if (!status) {
1137 MEDIA_ERR_LOG("CaptureSession::StartFocus Failed to set trigger");
1138 return CameraErrorCode::SUCCESS;
1139 }
1140
1141 triggerId++;
1142 ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_AF_TRIGGER_ID, &item);
1143 if (ret == CAM_META_ITEM_NOT_FOUND) {
1144 status = changedMetadata_->addEntry(OHOS_CONTROL_AF_TRIGGER_ID, &triggerId, count);
1145 } else if (ret == CAM_META_SUCCESS) {
1146 status = changedMetadata_->updateEntry(OHOS_CONTROL_AF_TRIGGER_ID, &triggerId, count);
1147 }
1148
1149 if (!status) {
1150 MEDIA_ERR_LOG("CaptureSession::SetFocusMode Failed to set trigger Id");
1151 return CameraErrorCode::SUCCESS;
1152 }
1153 return CameraErrorCode::SUCCESS;
1154 }
1155
SetFocusMode(FocusMode focusMode)1156 int32_t CaptureSession::SetFocusMode(FocusMode focusMode)
1157 {
1158 CAMERA_SYNC_TRACE;
1159 if (!IsSessionCommited()) {
1160 MEDIA_ERR_LOG("CaptureSession::SetFocusMode Session is not Commited");
1161 return CameraErrorCode::SESSION_NOT_CONFIG;
1162 }
1163 if (changedMetadata_ == nullptr) {
1164 MEDIA_ERR_LOG("CaptureSession::SetFocusMode Need to call LockForControl() before setting camera properties");
1165 return CameraErrorCode::SUCCESS;
1166 }
1167 uint8_t focus = FOCUS_MODE_LOCKED;
1168 auto itr = fwToMetaFocusMode_.find(focusMode);
1169 if (itr == fwToMetaFocusMode_.end()) {
1170 MEDIA_ERR_LOG("CaptureSession::SetExposureMode Unknown exposure mode");
1171 } else {
1172 focus = itr->second;
1173 }
1174 bool status = false;
1175 int32_t ret;
1176 uint32_t count = 1;
1177 camera_metadata_item_t item;
1178
1179 MEDIA_DEBUG_LOG("CaptureSession::SetFocusMode Focus mode: %{public}d", focusMode);
1180
1181 ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_FOCUS_MODE, &item);
1182 if (ret == CAM_META_ITEM_NOT_FOUND) {
1183 status = changedMetadata_->addEntry(OHOS_CONTROL_FOCUS_MODE, &focus, count);
1184 } else if (ret == CAM_META_SUCCESS) {
1185 status = changedMetadata_->updateEntry(OHOS_CONTROL_FOCUS_MODE, &focus, count);
1186 }
1187
1188 if (!status) {
1189 MEDIA_ERR_LOG("CaptureSession::SetFocusMode Failed to set focus mode");
1190 }
1191 return CameraErrorCode::SUCCESS;
1192 }
1193
GetFocusMode()1194 FocusMode CaptureSession::GetFocusMode()
1195 {
1196 if (!IsSessionCommited()) {
1197 MEDIA_ERR_LOG("CaptureSession::GetFocusMode Session is not Commited");
1198 return FOCUS_MODE_MANUAL;
1199 }
1200 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1201 MEDIA_ERR_LOG("CaptureSession::GetFocusMode camera device is null");
1202 return FOCUS_MODE_MANUAL;
1203 }
1204 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1205 camera_metadata_item_t item;
1206 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_FOCUS_MODE, &item);
1207 if (ret != CAM_META_SUCCESS) {
1208 MEDIA_ERR_LOG("CaptureSession::GetFocusMode Failed with return code %{public}d", ret);
1209 return FOCUS_MODE_MANUAL;
1210 }
1211 auto itr = metaToFwFocusMode_.find(static_cast<camera_focus_mode_enum_t>(item.data.u8[0]));
1212 if (itr != metaToFwFocusMode_.end()) {
1213 return itr->second;
1214 }
1215 return FOCUS_MODE_MANUAL;
1216 }
1217
GetFocusMode(FocusMode & focusMode)1218 int32_t CaptureSession::GetFocusMode(FocusMode &focusMode)
1219 {
1220 focusMode = FOCUS_MODE_MANUAL;
1221 if (!IsSessionCommited()) {
1222 MEDIA_ERR_LOG("CaptureSession::GetFocusMode Session is not Commited");
1223 return CameraErrorCode::SESSION_NOT_CONFIG;
1224 }
1225 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1226 MEDIA_ERR_LOG("CaptureSession::GetFocusMode camera device is null");
1227 return CameraErrorCode::SUCCESS;
1228 }
1229 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1230 camera_metadata_item_t item;
1231 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_FOCUS_MODE, &item);
1232 if (ret != CAM_META_SUCCESS) {
1233 MEDIA_ERR_LOG("CaptureSession::GetFocusMode Failed with return code %{public}d", ret);
1234 return CameraErrorCode::SUCCESS;
1235 }
1236 auto itr = metaToFwFocusMode_.find(static_cast<camera_focus_mode_enum_t>(item.data.u8[0]));
1237 if (itr != metaToFwFocusMode_.end()) {
1238 focusMode = itr->second;
1239 return CameraErrorCode::SUCCESS;
1240 }
1241 return CameraErrorCode::SUCCESS;
1242 }
1243
SetFocusPoint(Point focusPoint)1244 int32_t CaptureSession::SetFocusPoint(Point focusPoint)
1245 {
1246 if (!IsSessionCommited()) {
1247 MEDIA_ERR_LOG("CaptureSession::SetFocusPoint Session is not Commited");
1248 return CameraErrorCode::SESSION_NOT_CONFIG;
1249 }
1250 if (changedMetadata_ == nullptr) {
1251 MEDIA_ERR_LOG("CaptureSession::SetFocusPoint Need to call LockForControl() before setting camera properties");
1252 return CameraErrorCode::SUCCESS;
1253 }
1254 Point focusVerifyPoint = VerifyFocusCorrectness(focusPoint);
1255 Point unifyFocusPoint = CoordinateTransform(focusVerifyPoint);
1256 bool status = false;
1257 float FocusArea[2] = {unifyFocusPoint.x, unifyFocusPoint.y};
1258 camera_metadata_item_t item;
1259
1260 int ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_AF_REGIONS, &item);
1261 if (ret == CAM_META_ITEM_NOT_FOUND) {
1262 status = changedMetadata_->addEntry(OHOS_CONTROL_AF_REGIONS, FocusArea,
1263 sizeof(FocusArea) / sizeof(FocusArea[0]));
1264 } else if (ret == CAM_META_SUCCESS) {
1265 status = changedMetadata_->updateEntry(OHOS_CONTROL_AF_REGIONS, FocusArea,
1266 sizeof(FocusArea) / sizeof(FocusArea[0]));
1267 }
1268
1269 if (!status) {
1270 MEDIA_ERR_LOG("CaptureSession::SetFocusPoint Failed to set Focus Area");
1271 }
1272 return CameraErrorCode::SUCCESS;
1273 }
1274
CoordinateTransform(Point point)1275 Point CaptureSession::CoordinateTransform(Point point)
1276 {
1277 MEDIA_DEBUG_LOG("CaptureSession::CoordinateTransform begin x: %{public}f, y: %{public}f", point.x, point.y);
1278 Point unifyPoint = point;
1279 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1280 MEDIA_ERR_LOG("CaptureSession::CoordinateTransform cameraInput is nullptr");
1281 return unifyPoint;
1282 }
1283 if (inputDevice_->GetCameraDeviceInfo()->GetPosition() == CAMERA_POSITION_FRONT) {
1284 unifyPoint.x = 1 - unifyPoint.x; // flip horizontally
1285 }
1286 MEDIA_DEBUG_LOG("CaptureSession::CoordinateTransform end x: %{public}f, y: %{public}f",
1287 unifyPoint.x, unifyPoint.y);
1288 return unifyPoint;
1289 }
1290
VerifyFocusCorrectness(Point point)1291 Point CaptureSession::VerifyFocusCorrectness(Point point)
1292 {
1293 MEDIA_DEBUG_LOG("CaptureSession::VerifyFocusCorrectness begin x: %{public}f, y: %{public}f", point.x, point.y);
1294 float minPoint = 0.0000001;
1295 float maxPoint = 1;
1296 Point VerifyPoint = point;
1297 if (VerifyPoint.x >= -minPoint && VerifyPoint.x <= minPoint) {
1298 VerifyPoint.x = minPoint;
1299 } else if (VerifyPoint.x > maxPoint) {
1300 VerifyPoint.x = maxPoint;
1301 }
1302 if (VerifyPoint.y >= -minPoint && VerifyPoint.y <= minPoint) {
1303 VerifyPoint.y = minPoint;
1304 } else if (VerifyPoint.y > maxPoint) {
1305 VerifyPoint.y = maxPoint;
1306 }
1307 MEDIA_DEBUG_LOG("CaptureSession::VerifyFocusCorrectness end x: %{public}f, y: %{public}f",
1308 VerifyPoint.x, VerifyPoint.y);
1309 return VerifyPoint;
1310 }
1311
GetFocusPoint()1312 Point CaptureSession::GetFocusPoint()
1313 {
1314 Point focusPoint = {0, 0};
1315 if (!IsSessionCommited()) {
1316 MEDIA_ERR_LOG("CaptureSession::GetFocusPoint Session is not Commited");
1317 return focusPoint;
1318 }
1319 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1320 MEDIA_ERR_LOG("CaptureSession::GetFocusPoint camera device is null");
1321 return focusPoint;
1322 }
1323 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1324 camera_metadata_item_t item;
1325 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_AF_REGIONS, &item);
1326 if (ret != CAM_META_SUCCESS) {
1327 MEDIA_ERR_LOG("CaptureSession::GetFocusPoint Failed with return code %{public}d", ret);
1328 return focusPoint;
1329 }
1330 focusPoint.x = item.data.f[0];
1331 focusPoint.y = item.data.f[1];
1332 Point unifyFocusPoint = CoordinateTransform(focusPoint);
1333 return unifyFocusPoint;
1334 }
1335
GetFocusPoint(Point & focusPoint)1336 int32_t CaptureSession::GetFocusPoint(Point &focusPoint)
1337 {
1338 focusPoint.x = 0;
1339 focusPoint.y = 0;
1340 if (!IsSessionCommited()) {
1341 MEDIA_ERR_LOG("CaptureSession::GetFocusPoint Session is not Commited");
1342 return CameraErrorCode::SESSION_NOT_CONFIG;
1343 }
1344 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1345 MEDIA_ERR_LOG("CaptureSession::GetFocusPoint camera device is null");
1346 return CameraErrorCode::SUCCESS;
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_CONTROL_AF_REGIONS, &item);
1351 if (ret != CAM_META_SUCCESS) {
1352 MEDIA_ERR_LOG("CaptureSession::GetFocusPoint Failed with return code %{public}d", ret);
1353 return CameraErrorCode::SUCCESS;
1354 }
1355 focusPoint.x = item.data.f[0];
1356 focusPoint.y = item.data.f[1];
1357 focusPoint = CoordinateTransform(focusPoint);
1358 return CameraErrorCode::SUCCESS;
1359 }
1360
GetFocalLength()1361 float CaptureSession::GetFocalLength()
1362 {
1363 if (!IsSessionCommited()) {
1364 MEDIA_ERR_LOG("CaptureSession::GetFocalLength Session is not Commited");
1365 return 0;
1366 }
1367 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1368 MEDIA_ERR_LOG("CaptureSession::GetFocalLength camera device is null");
1369 return 0;
1370 }
1371 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1372 camera_metadata_item_t item;
1373 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FOCAL_LENGTH, &item);
1374 if (ret != CAM_META_SUCCESS) {
1375 MEDIA_ERR_LOG("CaptureSession::GetFocalLength Failed with return code %{public}d", ret);
1376 return 0;
1377 }
1378 return static_cast<float>(item.data.f[0]);
1379 }
1380
GetFocalLength(float & focalLength)1381 int32_t CaptureSession::GetFocalLength(float &focalLength)
1382 {
1383 focalLength = 0;
1384 if (!IsSessionCommited()) {
1385 MEDIA_ERR_LOG("CaptureSession::GetFocalLength Session is not Commited");
1386 return CameraErrorCode::SESSION_NOT_CONFIG;
1387 }
1388 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1389 MEDIA_ERR_LOG("CaptureSession::GetFocalLength camera device is null");
1390 return CameraErrorCode::SUCCESS;
1391 }
1392 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1393 camera_metadata_item_t item;
1394 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FOCAL_LENGTH, &item);
1395 if (ret != CAM_META_SUCCESS) {
1396 MEDIA_ERR_LOG("CaptureSession::GetFocalLength Failed with return code %{public}d", ret);
1397 return CameraErrorCode::SUCCESS;
1398 }
1399 focalLength = static_cast<float>(item.data.f[0]);
1400 return CameraErrorCode::SUCCESS;
1401 }
1402
ProcessAutoFocusUpdates(const std::shared_ptr<Camera::CameraMetadata> & result)1403 void CaptureSession::ProcessAutoFocusUpdates(const std::shared_ptr<Camera::CameraMetadata> &result)
1404 {
1405 camera_metadata_item_t item;
1406 common_metadata_header_t* metadata = result->get();
1407 int ret = Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_FOCUS_MODE, &item);
1408 if (ret == CAM_META_SUCCESS) {
1409 MEDIA_DEBUG_LOG("Focus mode: %{public}d", item.data.u8[0]);
1410 }
1411 ret = Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_FOCUS_STATE, &item);
1412 if (ret == CAM_META_SUCCESS) {
1413 MEDIA_INFO_LOG("Focus state: %{public}d", item.data.u8[0]);
1414 if (focusCallback_ != nullptr) {
1415 auto itr = metaToFwFocusState_.find(static_cast<camera_focus_state_t>(item.data.u8[0]));
1416 if (itr != metaToFwFocusState_.end()) {
1417 focusCallback_->OnFocusState(itr->second);
1418 }
1419 }
1420 }
1421 }
1422
GetSupportedFlashModes()1423 std::vector<FlashMode> CaptureSession::GetSupportedFlashModes()
1424 {
1425 std::vector<FlashMode> supportedFlashModes = {};
1426 if (!IsSessionCommited()) {
1427 MEDIA_ERR_LOG("CaptureSession::GetSupportedFlashModes Session is not Commited");
1428 return supportedFlashModes;
1429 }
1430 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1431 MEDIA_ERR_LOG("CaptureSession::GetSupportedFlashModes camera device is null");
1432 return supportedFlashModes;
1433 }
1434 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1435 camera_metadata_item_t item;
1436 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FLASH_MODES, &item);
1437 if (ret != CAM_META_SUCCESS) {
1438 MEDIA_ERR_LOG("CaptureSession::GetSupportedFlashModes Failed with return code %{public}d", ret);
1439 return supportedFlashModes;
1440 }
1441 for (uint32_t i = 0; i < item.count; i++) {
1442 auto itr = metaToFwFlashMode_.find(static_cast<camera_flash_mode_enum_t>(item.data.u8[i]));
1443 if (itr != metaToFwFlashMode_.end()) {
1444 supportedFlashModes.emplace_back(itr->second);
1445 }
1446 }
1447 return supportedFlashModes;
1448 }
1449
GetSupportedFlashModes(std::vector<FlashMode> & supportedFlashModes)1450 int32_t CaptureSession::GetSupportedFlashModes(std::vector<FlashMode> &supportedFlashModes)
1451 {
1452 supportedFlashModes.clear();
1453 if (!IsSessionCommited()) {
1454 MEDIA_ERR_LOG("CaptureSession::GetSupportedFlashModes Session is not Commited");
1455 return CameraErrorCode::SESSION_NOT_CONFIG;
1456 }
1457 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1458 MEDIA_ERR_LOG("CaptureSession::GetSupportedFlashModes camera device is null");
1459 return CameraErrorCode::SUCCESS;
1460 }
1461 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1462 camera_metadata_item_t item;
1463 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FLASH_MODES, &item);
1464 if (ret != CAM_META_SUCCESS) {
1465 MEDIA_ERR_LOG("CaptureSession::GetSupportedFlashModes Failed with return code %{public}d", ret);
1466 return CameraErrorCode::SUCCESS;
1467 }
1468 for (uint32_t i = 0; i < item.count; i++) {
1469 auto itr = metaToFwFlashMode_.find(static_cast<camera_flash_mode_enum_t>(item.data.u8[i]));
1470 if (itr != metaToFwFlashMode_.end()) {
1471 supportedFlashModes.emplace_back(itr->second);
1472 }
1473 }
1474 return CameraErrorCode::SUCCESS;
1475 }
1476
GetFlashMode()1477 FlashMode CaptureSession::GetFlashMode()
1478 {
1479 if (!IsSessionCommited()) {
1480 MEDIA_ERR_LOG("CaptureSession::GetFlashMode Session is not Commited");
1481 return FLASH_MODE_CLOSE;
1482 }
1483 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1484 MEDIA_ERR_LOG("CaptureSession::GetFlashMode camera device is null");
1485 return FLASH_MODE_CLOSE;
1486 }
1487 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1488 camera_metadata_item_t item;
1489 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_FLASH_MODE, &item);
1490 if (ret != CAM_META_SUCCESS) {
1491 MEDIA_ERR_LOG("CaptureSession::GetFlashMode Failed with return code %{public}d", ret);
1492 return FLASH_MODE_CLOSE;
1493 }
1494 auto itr = metaToFwFlashMode_.find(static_cast<camera_flash_mode_enum_t>(item.data.u8[0]));
1495 if (itr != metaToFwFlashMode_.end()) {
1496 return itr->second;
1497 }
1498
1499 return FLASH_MODE_CLOSE;
1500 }
1501
GetFlashMode(FlashMode & flashMode)1502 int32_t CaptureSession::GetFlashMode(FlashMode &flashMode)
1503 {
1504 flashMode = FLASH_MODE_CLOSE;
1505 if (!IsSessionCommited()) {
1506 MEDIA_ERR_LOG("CaptureSession::GetFlashMode Session is not Commited");
1507 return CameraErrorCode::SESSION_NOT_CONFIG;
1508 }
1509 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1510 MEDIA_ERR_LOG("CaptureSession::GetFlashMode camera device is null");
1511 return CameraErrorCode::SUCCESS;
1512 }
1513 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1514 camera_metadata_item_t item;
1515 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_FLASH_MODE, &item);
1516 if (ret != CAM_META_SUCCESS) {
1517 MEDIA_ERR_LOG("CaptureSession::GetFlashMode Failed with return code %{public}d", ret);
1518 return CameraErrorCode::SUCCESS;
1519 }
1520 auto itr = metaToFwFlashMode_.find(static_cast<camera_flash_mode_enum_t>(item.data.u8[0]));
1521 if (itr != metaToFwFlashMode_.end()) {
1522 flashMode = itr->second;
1523 return CameraErrorCode::SUCCESS;
1524 }
1525
1526 return CameraErrorCode::SUCCESS;
1527 }
1528
SetFlashMode(FlashMode flashMode)1529 int32_t CaptureSession::SetFlashMode(FlashMode flashMode)
1530 {
1531 CAMERA_SYNC_TRACE;
1532 if (!IsSessionCommited()) {
1533 MEDIA_ERR_LOG("CaptureSession::SetFlashMode Session is not Commited");
1534 return CameraErrorCode::SESSION_NOT_CONFIG;
1535 }
1536 if (changedMetadata_ == nullptr) {
1537 MEDIA_ERR_LOG("CaptureSession::SetFlashMode Need to call LockForControl() before setting camera properties");
1538 return CameraErrorCode::SUCCESS;
1539 }
1540 uint8_t flash = fwToMetaFlashMode_.at(FLASH_MODE_CLOSE);
1541 auto itr = fwToMetaFlashMode_.find(flashMode);
1542 if (itr == fwToMetaFlashMode_.end()) {
1543 MEDIA_ERR_LOG("CaptureSession::SetExposureMode Unknown exposure mode");
1544 } else {
1545 flash = itr->second;
1546 }
1547
1548 bool status = false;
1549 uint32_t count = 1;
1550 camera_metadata_item_t item;
1551 int ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_FLASH_MODE, &item);
1552 if (ret == CAM_META_ITEM_NOT_FOUND) {
1553 status = changedMetadata_->addEntry(OHOS_CONTROL_FLASH_MODE, &flash, count);
1554 } else if (ret == CAM_META_SUCCESS) {
1555 status = changedMetadata_->updateEntry(OHOS_CONTROL_FLASH_MODE, &flash, count);
1556 }
1557
1558 if (!status) {
1559 MEDIA_ERR_LOG("CaptureSession::SetFlashMode Failed to set flash mode");
1560 return CameraErrorCode::SUCCESS;
1561 }
1562
1563 if (flashMode == FLASH_MODE_CLOSE) {
1564 POWERMGR_SYSEVENT_FLASH_OFF();
1565 } else {
1566 POWERMGR_SYSEVENT_FLASH_ON();
1567 }
1568 return CameraErrorCode::SUCCESS;
1569 }
1570
IsFlashModeSupported(FlashMode flashMode)1571 bool CaptureSession::IsFlashModeSupported(FlashMode flashMode)
1572 {
1573 std::vector<FlashMode> vecSupportedFlashModeList;
1574 vecSupportedFlashModeList = this->GetSupportedFlashModes();
1575 if (find(vecSupportedFlashModeList.begin(), vecSupportedFlashModeList.end(), flashMode) !=
1576 vecSupportedFlashModeList.end()) {
1577 return true;
1578 }
1579
1580 return false;
1581 }
1582
IsFlashModeSupported(FlashMode flashMode,bool & isSupported)1583 int32_t CaptureSession::IsFlashModeSupported(FlashMode flashMode, bool &isSupported)
1584 {
1585 if (!IsSessionCommited()) {
1586 MEDIA_ERR_LOG("CaptureSession::IsFlashModeSupported Session is not Commited");
1587 return CameraErrorCode::SESSION_NOT_CONFIG;
1588 }
1589 std::vector<FlashMode> vecSupportedFlashModeList;
1590 vecSupportedFlashModeList = this->GetSupportedFlashModes();
1591 if (find(vecSupportedFlashModeList.begin(), vecSupportedFlashModeList.end(), flashMode) !=
1592 vecSupportedFlashModeList.end()) {
1593 isSupported = true;
1594 return CameraErrorCode::SUCCESS;
1595 }
1596 isSupported = false;
1597 return CameraErrorCode::SUCCESS;
1598 }
1599
HasFlash()1600 bool CaptureSession::HasFlash()
1601 {
1602 std::vector<FlashMode> vecSupportedFlashModeList;
1603 vecSupportedFlashModeList = this->GetSupportedFlashModes();
1604 if (vecSupportedFlashModeList.empty()) {
1605 return false;
1606 }
1607 return true;
1608 }
1609
HasFlash(bool & hasFlash)1610 int32_t CaptureSession::HasFlash(bool &hasFlash)
1611 {
1612 if (!IsSessionCommited()) {
1613 MEDIA_ERR_LOG("CaptureSession::HasFlash Session is not Commited");
1614 return CameraErrorCode::SESSION_NOT_CONFIG;
1615 }
1616 std::vector<FlashMode> vecSupportedFlashModeList;
1617 vecSupportedFlashModeList = this->GetSupportedFlashModes();
1618 if (vecSupportedFlashModeList.empty()) {
1619 hasFlash = false;
1620 return CameraErrorCode::SUCCESS;
1621 }
1622 hasFlash = true;
1623 return CameraErrorCode::SUCCESS;
1624 }
1625
GetZoomRatioRange()1626 std::vector<float> CaptureSession::GetZoomRatioRange()
1627 {
1628 if (!IsSessionCommited()) {
1629 MEDIA_ERR_LOG("CaptureSession::GetZoomRatioRange Session is not Commited");
1630 return {};
1631 }
1632 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1633 MEDIA_ERR_LOG("CaptureSession::GetZoomRatioRange camera device is null");
1634 return {};
1635 }
1636 return inputDevice_->GetCameraDeviceInfo()->GetZoomRatioRange();
1637 }
1638
GetZoomRatioRange(std::vector<float> & zoomRatioRange)1639 int32_t CaptureSession::GetZoomRatioRange(std::vector<float> &zoomRatioRange)
1640 {
1641 zoomRatioRange.clear();
1642 if (!IsSessionCommited()) {
1643 MEDIA_ERR_LOG("CaptureSession::GetZoomRatioRange Session is not Commited");
1644 return CameraErrorCode::SESSION_NOT_CONFIG;
1645 }
1646 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1647 MEDIA_ERR_LOG("CaptureSession::GetZoomRatioRange camera device is null");
1648 return CameraErrorCode::SUCCESS;
1649 }
1650 zoomRatioRange = inputDevice_->GetCameraDeviceInfo()->GetZoomRatioRange();
1651 return CameraErrorCode::SUCCESS;
1652 }
1653
GetZoomRatio()1654 float CaptureSession::GetZoomRatio()
1655 {
1656 if (!IsSessionCommited()) {
1657 MEDIA_ERR_LOG("CaptureSession::GetZoomRatio Session is not Commited");
1658 return 0;
1659 }
1660 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1661 MEDIA_ERR_LOG("CaptureSession::GetZoomRatio camera device is null");
1662 return 0;
1663 }
1664 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1665 camera_metadata_item_t item;
1666 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_ZOOM_RATIO, &item);
1667 if (ret != CAM_META_SUCCESS) {
1668 MEDIA_ERR_LOG("CaptureSession::GetZoomRatio Failed with return code %{public}d", ret);
1669 return 0;
1670 }
1671 return static_cast<float>(item.data.f[0]);
1672 }
1673
GetZoomRatio(float & zoomRatio)1674 int32_t CaptureSession::GetZoomRatio(float &zoomRatio)
1675 {
1676 zoomRatio = 0;
1677 if (!IsSessionCommited()) {
1678 MEDIA_ERR_LOG("CaptureSession::GetZoomRatio Session is not Commited");
1679 return CameraErrorCode::SESSION_NOT_CONFIG;
1680 }
1681 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1682 MEDIA_ERR_LOG("CaptureSession::GetZoomRatio camera device is null");
1683 return CameraErrorCode::SUCCESS;
1684 }
1685 std::shared_ptr<Camera::CameraMetadata> metadata = inputDevice_->GetCameraDeviceInfo()->GetMetadata();
1686 camera_metadata_item_t item;
1687 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_ZOOM_RATIO, &item);
1688 if (ret != CAM_META_SUCCESS) {
1689 MEDIA_ERR_LOG("CaptureSession::GetZoomRatio Failed with return code %{public}d", ret);
1690 return CameraErrorCode::SUCCESS;
1691 }
1692 zoomRatio = static_cast<float>(item.data.f[0]);
1693 return CameraErrorCode::SUCCESS;
1694 }
1695
SetCropRegion(float zoomRatio)1696 int32_t CaptureSession::SetCropRegion(float zoomRatio)
1697 {
1698 bool status = false;
1699 int32_t leftIndex = 0;
1700 int32_t topIndex = 1;
1701 int32_t rightIndex = 2;
1702 int32_t bottomIndex = 3;
1703 int32_t factor = 2;
1704 const uint32_t arrayCount = 4;
1705 int32_t cropRegion[arrayCount] = {};
1706 camera_metadata_item_t item;
1707 if (!IsSessionCommited()) {
1708 MEDIA_ERR_LOG("CaptureSession::SetCropRegion Session is not Commited");
1709 return CameraErrorCode::SESSION_NOT_CONFIG;
1710 }
1711 if (zoomRatio == 0 || !inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1712 MEDIA_ERR_LOG("CaptureSession::SetCropRegion Invalid zoom ratio or camera device is null");
1713 return CameraErrorCode::SUCCESS;
1714 }
1715 int32_t ret = Camera::FindCameraMetadataItem(
1716 inputDevice_->GetCameraDeviceInfo()->GetMetadata()->get(), OHOS_SENSOR_INFO_ACTIVE_ARRAY_SIZE, &item);
1717 if (ret != CAM_META_SUCCESS) {
1718 MEDIA_ERR_LOG("CaptureSession::SetCropRegion Failed get sensor active array, return code %{public}d", ret);
1719 return CameraErrorCode::SUCCESS;
1720 }
1721 if (item.count != arrayCount) {
1722 MEDIA_ERR_LOG("CaptureSession::SetCropRegion Invalid sensor active array size count: %{public}u", item.count);
1723 return CameraErrorCode::SUCCESS;
1724 }
1725 MEDIA_DEBUG_LOG("CaptureSession::SetCropRegion Sensor active array left: %{public}d, top: %{public}d, "
1726 "right: %{public}d, bottom: %{public}d", item.data.i32[leftIndex], item.data.i32[topIndex],
1727 item.data.i32[rightIndex], item.data.i32[bottomIndex]);
1728 int32_t sensorRight = item.data.i32[rightIndex];
1729 int32_t sensorBottom = item.data.i32[bottomIndex];
1730 cropRegion[leftIndex] = (sensorRight - (sensorRight / zoomRatio)) / factor;
1731 cropRegion[topIndex] = (sensorBottom - (sensorBottom / zoomRatio)) / factor;
1732 cropRegion[rightIndex] = cropRegion[leftIndex] + (sensorRight / zoomRatio);
1733 cropRegion[bottomIndex] = cropRegion[topIndex] + (sensorBottom / zoomRatio);
1734 MEDIA_DEBUG_LOG("CaptureSession::SetCropRegion Crop region left: %{public}d, top: %{public}d, "
1735 "right: %{public}d, bottom: %{public}d", cropRegion[leftIndex], cropRegion[topIndex],
1736 cropRegion[rightIndex], cropRegion[bottomIndex]);
1737 ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_ZOOM_CROP_REGION, &item);
1738 if (ret == CAM_META_ITEM_NOT_FOUND) {
1739 status = changedMetadata_->addEntry(OHOS_CONTROL_ZOOM_CROP_REGION, cropRegion, arrayCount);
1740 } else if (ret == CAM_META_SUCCESS) {
1741 status = changedMetadata_->updateEntry(OHOS_CONTROL_ZOOM_CROP_REGION, cropRegion, arrayCount);
1742 }
1743 if (!status) {
1744 MEDIA_ERR_LOG("CaptureSession::SetCropRegion Failed to set zoom crop region");
1745 }
1746 return CameraErrorCode::SUCCESS;
1747 }
1748
SetZoomRatio(float zoomRatio)1749 int32_t CaptureSession::SetZoomRatio(float zoomRatio)
1750 {
1751 CAMERA_SYNC_TRACE;
1752 if (!IsSessionCommited()) {
1753 MEDIA_ERR_LOG("CaptureSession::SetZoomRatio Session is not Commited");
1754 return CameraErrorCode::SESSION_NOT_CONFIG;
1755 }
1756 if (changedMetadata_ == nullptr) {
1757 MEDIA_ERR_LOG("CaptureSession::SetZoomRatio Need to call LockForControl() before setting camera properties");
1758 return CameraErrorCode::SUCCESS;
1759 }
1760
1761 bool status = false;
1762 int32_t ret;
1763 int32_t minIndex = 0;
1764 int32_t maxIndex = 1;
1765 int32_t count = 1;
1766 camera_metadata_item_t item;
1767 MEDIA_DEBUG_LOG("CaptureSession::SetZoomRatio Zoom ratio: %{public}f", zoomRatio);
1768 if (!inputDevice_ || !inputDevice_->GetCameraDeviceInfo()) {
1769 MEDIA_ERR_LOG("CaptureSession::SetZoomRatio camera device is null");
1770 return CameraErrorCode::SUCCESS;
1771 }
1772 std::vector<float> zoomRange = inputDevice_->GetCameraDeviceInfo()->GetZoomRatioRange();
1773 if (zoomRange.empty()) {
1774 MEDIA_ERR_LOG("CaptureSession::SetZoomRatio Zoom range is empty");
1775 return CameraErrorCode::SUCCESS;
1776 }
1777 if (zoomRatio < zoomRange[minIndex]) {
1778 MEDIA_DEBUG_LOG("CaptureSession::SetZoomRatio Zoom ratio: %{public}f is lesser than minimum zoom: %{public}f",
1779 zoomRatio, zoomRange[minIndex]);
1780 zoomRatio = zoomRange[minIndex];
1781 } else if (zoomRatio > zoomRange[maxIndex]) {
1782 MEDIA_DEBUG_LOG("CaptureSession::SetZoomRatio Zoom ratio: %{public}f is greater than maximum zoom: %{public}f",
1783 zoomRatio, zoomRange[maxIndex]);
1784 zoomRatio = zoomRange[maxIndex];
1785 }
1786
1787 if (zoomRatio == 0) {
1788 MEDIA_ERR_LOG("CaptureSession::SetZoomRatio Invalid zoom ratio");
1789 return CameraErrorCode::SUCCESS;
1790 }
1791
1792 ret = Camera::FindCameraMetadataItem(changedMetadata_->get(), OHOS_CONTROL_ZOOM_RATIO, &item);
1793 if (ret == CAM_META_ITEM_NOT_FOUND) {
1794 status = changedMetadata_->addEntry(OHOS_CONTROL_ZOOM_RATIO, &zoomRatio, count);
1795 } else if (ret == CAM_META_SUCCESS) {
1796 status = changedMetadata_->updateEntry(OHOS_CONTROL_ZOOM_RATIO, &zoomRatio, count);
1797 }
1798
1799 if (!status) {
1800 MEDIA_ERR_LOG("CaptureSession::SetZoomRatio Failed to set zoom mode");
1801 }
1802 return CameraErrorCode::SUCCESS;
1803 }
1804
SetCaptureMetadataObjectTypes(std::set<camera_face_detect_mode_t> metadataObjectTypes)1805 void CaptureSession::SetCaptureMetadataObjectTypes(std::set<camera_face_detect_mode_t> metadataObjectTypes)
1806 {
1807 if (inputDevice_ == nullptr) {
1808 MEDIA_ERR_LOG("SetCaptureMetadataObjectTypes: inputDevice is null");
1809 return;
1810 }
1811 uint32_t count = 0;
1812 uint8_t objectTypes[metadataObjectTypes.size()];
1813 for (const auto &type : metadataObjectTypes) {
1814 objectTypes[count++] = type;
1815 }
1816 this->LockForControl();
1817 if (!this->changedMetadata_->addEntry(OHOS_STATISTICS_FACE_DETECT_SWITCH, objectTypes, count)) {
1818 MEDIA_ERR_LOG("SetCaptureMetadataObjectTypes: Failed to add detect object types to changed metadata");
1819 }
1820 this->UnlockForControl();
1821 }
1822
SetFrameRateRange(const std::vector<int32_t> & frameRateRange)1823 void CaptureSession::SetFrameRateRange(const std::vector<int32_t>& frameRateRange)
1824 {
1825 if (!IsSessionCommited()) {
1826 MEDIA_ERR_LOG("UpdateConfigSetting: inputDevice is null");
1827 return;
1828 }
1829
1830 std::vector<int32_t> videoFrameRateRange = frameRateRange;
1831 this->LockForControl();
1832 if (!this->changedMetadata_->addEntry(OHOS_CONTROL_FPS_RANGES,
1833 videoFrameRateRange.data(), videoFrameRateRange.size())) {
1834 MEDIA_ERR_LOG("Failed to SetFrameRateRange");
1835 }
1836 this->UnlockForControl();
1837 }
1838
IsSessionConfiged()1839 bool CaptureSession::IsSessionConfiged()
1840 {
1841 bool isSessionConfiged = false;
1842 if (captureSession_) {
1843 CaptureSessionState currentState;
1844 captureSession_->GetSessionState(currentState);
1845 isSessionConfiged = (currentState == CaptureSessionState::SESSION_CONFIG_INPROGRESS);
1846 }
1847 return isSessionConfiged;
1848 }
1849
IsSessionCommited()1850 bool CaptureSession::IsSessionCommited()
1851 {
1852 bool isCommitConfig = false;
1853 if (captureSession_) {
1854 CaptureSessionState currentState;
1855 captureSession_->GetSessionState(currentState);
1856 isCommitConfig = (currentState == CaptureSessionState::SESSION_CONFIG_COMMITTED);
1857 }
1858 return isCommitConfig;
1859 }
1860 } // CameraStandard
1861 } // OHOS
1862