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/profession_session.h"
17 #include "camera_log.h"
18 #include "camera_metadata_operator.h"
19 #include "camera_util.h"
20 #include "input/camera_manager.h"
21 #include "metadata_common_utils.h"
22 #include <algorithm>
23 #include <cstdint>
24
25 namespace OHOS {
26 namespace CameraStandard {
27 constexpr int32_t DEFAULT_ITEMS = 10;
28 constexpr int32_t DEFAULT_DATA_LENGTH = 100;
29
~ProfessionSession()30 ProfessionSession::~ProfessionSession()
31 {
32 exposureInfoCallback_ = nullptr;
33 isoInfoCallback_ = nullptr;
34 apertureInfoCallback_ = nullptr;
35 luminationInfoCallback_ = nullptr;
36 }
37 // metering mode
38 const std::unordered_map<camera_meter_mode_t, MeteringMode> ProfessionSession::metaMeteringModeMap_ = {
39 {OHOS_CAMERA_SPOT_METERING, METERING_MODE_SPOT},
40 {OHOS_CAMERA_REGION_METERING, METERING_MODE_REGION},
41 {OHOS_CAMERA_OVERALL_METERING, METERING_MODE_OVERALL},
42 {OHOS_CAMERA_CENTER_WEIGHTED_METERING, METERING_MODE_CENTER_WEIGHTED}
43 };
44
45 const std::unordered_map<MeteringMode, camera_meter_mode_t> ProfessionSession::fwkMeteringModeMap_ = {
46 {METERING_MODE_SPOT, OHOS_CAMERA_SPOT_METERING},
47 {METERING_MODE_REGION, OHOS_CAMERA_REGION_METERING},
48 {METERING_MODE_OVERALL, OHOS_CAMERA_OVERALL_METERING},
49 {METERING_MODE_CENTER_WEIGHTED, OHOS_CAMERA_CENTER_WEIGHTED_METERING}
50 };
51
52 // FocusAssistFlash mode
53 const std::unordered_map<camera_focus_assist_flash_mode_enum_t, FocusAssistFlashMode>
54 ProfessionSession::metaFocusAssistFlashModeMap_ = {
55 { OHOS_CAMERA_FOCUS_ASSIST_FLASH_MODE_DEFAULT, FOCUS_ASSIST_FLASH_MODE_DEFAULT },
56 { OHOS_CAMERA_FOCUS_ASSIST_FLASH_MODE_AUTO, FOCUS_ASSIST_FLASH_MODE_AUTO },
57 { OHOS_CAMERA_FOCUS_ASSIST_FLASH_MODE_ON, FOCUS_ASSIST_FLASH_MODE_ON },
58 { OHOS_CAMERA_FOCUS_ASSIST_FLASH_MODE_OFF, FOCUS_ASSIST_FLASH_MODE_OFF },
59 };
60 const std::unordered_map<FocusAssistFlashMode, camera_focus_assist_flash_mode_enum_t>
61 ProfessionSession::fwkFocusAssistFlashModeMap_ = {
62 { FOCUS_ASSIST_FLASH_MODE_DEFAULT, OHOS_CAMERA_FOCUS_ASSIST_FLASH_MODE_DEFAULT },
63 { FOCUS_ASSIST_FLASH_MODE_AUTO, OHOS_CAMERA_FOCUS_ASSIST_FLASH_MODE_AUTO },
64 { FOCUS_ASSIST_FLASH_MODE_ON, OHOS_CAMERA_FOCUS_ASSIST_FLASH_MODE_ON },
65 { FOCUS_ASSIST_FLASH_MODE_OFF, OHOS_CAMERA_FOCUS_ASSIST_FLASH_MODE_OFF },
66 };
67 // ExposureHintMode
68 const std::unordered_map<camera_exposure_hint_mode_enum_t, ExposureHintMode>
69 ProfessionSession::metaExposureHintModeMap_ = {
70 { OHOS_CAMERA_EXPOSURE_HINT_UNSUPPORTED, EXPOSURE_HINT_UNSUPPORTED },
71 { OHOS_CAMERA_EXPOSURE_HINT_MODE_ON, EXPOSURE_HINT_MODE_ON },
72 { OHOS_CAMERA_EXPOSURE_HINT_MODE_OFF, EXPOSURE_HINT_MODE_OFF },
73 };
74 const std::unordered_map<ExposureHintMode, camera_exposure_hint_mode_enum_t>
75 ProfessionSession::fwkExposureHintModeMap_ = {
76 { EXPOSURE_HINT_UNSUPPORTED, OHOS_CAMERA_EXPOSURE_HINT_UNSUPPORTED },
77 { EXPOSURE_HINT_MODE_ON, OHOS_CAMERA_EXPOSURE_HINT_MODE_ON },
78 { EXPOSURE_HINT_MODE_OFF, OHOS_CAMERA_EXPOSURE_HINT_MODE_OFF },
79 };
80 // metering mode
GetSupportedMeteringModes(std::vector<MeteringMode> & supportedMeteringModes)81 int32_t ProfessionSession::GetSupportedMeteringModes(std::vector<MeteringMode> &supportedMeteringModes)
82 {
83 supportedMeteringModes.clear();
84 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
85 "ProfessionSession::GetSupportedMeteringModes Session is not Commited");
86 auto inputDevice = GetInputDevice();
87 CHECK_RETURN_RET_ELOG(!inputDevice, CameraErrorCode::SUCCESS,
88 "ProfessionSession::GetSupportedMeteringModes camera device is null");
89 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
90 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
91 "ProfessionSession::GetSupportedMeteringModes camera deviceInfo is null");
92 std::shared_ptr<Camera::CameraMetadata> metadata = inputDeviceInfo->GetCachedMetadata();
93 camera_metadata_item_t item;
94 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_METER_MODES, &item);
95 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS, CameraErrorCode::SUCCESS,
96 "ProfessionSession::GetSupportedMeteringModes Failed with return code %{public}d", ret);
97 for (uint32_t i = 0; i < item.count; i++) {
98 auto itr = metaMeteringModeMap_.find(static_cast<camera_meter_mode_t>(item.data.u8[i]));
99 CHECK_EXECUTE(itr != metaMeteringModeMap_.end(), supportedMeteringModes.emplace_back(itr->second));
100 }
101 return CameraErrorCode::SUCCESS;
102 }
103
IsMeteringModeSupported(MeteringMode meteringMode,bool & isSupported)104 int32_t ProfessionSession::IsMeteringModeSupported(MeteringMode meteringMode, bool &isSupported)
105 {
106 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
107 "ProfessionSession::IsMeteringModeSupported Session is not Commited");
108 std::vector<MeteringMode> vecSupportedMeteringModeList;
109 (void)this->GetSupportedMeteringModes(vecSupportedMeteringModeList);
110 if (find(vecSupportedMeteringModeList.begin(), vecSupportedMeteringModeList.end(),
111 meteringMode) != vecSupportedMeteringModeList.end()) {
112 isSupported = true;
113 return CameraErrorCode::SUCCESS;
114 }
115 isSupported = false;
116 return CameraErrorCode::SUCCESS;
117 }
118
SetMeteringMode(MeteringMode mode)119 int32_t ProfessionSession::SetMeteringMode(MeteringMode mode)
120 {
121 CAMERA_SYNC_TRACE;
122 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
123 "ProfessionSession::SetMeteringMode Session is not Commited");
124 CHECK_RETURN_RET_ELOG(changedMetadata_ == nullptr, CameraErrorCode::SUCCESS,
125 "ProfessionSession::SetMeteringMode Need to call LockForControl() before setting camera properties");
126 // LCOV_EXCL_START
127 camera_meter_mode_t meteringMode = OHOS_CAMERA_SPOT_METERING;
128 auto itr = fwkMeteringModeMap_.find(mode);
129 if (itr == fwkMeteringModeMap_.end()) {
130 MEDIA_ERR_LOG("ProfessionSession::SetMeteringMode Unknown exposure mode");
131 } else {
132 meteringMode = itr->second;
133 }
134 MEDIA_DEBUG_LOG("ProfessionSession::SetMeteringMode metering mode: %{public}d", meteringMode);
135 bool status = AddOrUpdateMetadata(changedMetadata_, OHOS_CONTROL_METER_MODE, &meteringMode, 1);
136 CHECK_PRINT_ELOG(!status, "ProfessionSession::SetMeteringMode Failed to set focus mode");
137 return CameraErrorCode::SUCCESS;
138 // LCOV_EXCL_STOP
139 }
140
GetMeteringMode(MeteringMode & meteringMode)141 int32_t ProfessionSession::GetMeteringMode(MeteringMode &meteringMode)
142 {
143 meteringMode = METERING_MODE_SPOT;
144 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
145 "ProfessionSession::GetMeteringMode Session is not Commited");
146 auto inputDevice = GetInputDevice();
147 CHECK_RETURN_RET_ELOG(!inputDevice,
148 CameraErrorCode::SUCCESS, "ProfessionSession::GetMeteringMode camera device is null");
149 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
150 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
151 "ProfessionSession::GetSupportedMeteringModes camera deviceInfo is null");
152 std::shared_ptr<Camera::CameraMetadata> metadata = inputDeviceInfo->GetCachedMetadata();
153 camera_metadata_item_t item;
154 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_METER_MODE, &item);
155 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS, CameraErrorCode::SUCCESS,
156 "ProfessionSession::GetMeteringMode Failed with return code %{public}d", ret);
157 // LCOV_EXCL_START
158 auto itr = metaMeteringModeMap_.find(static_cast<camera_meter_mode_t>(item.data.u8[0]));
159 if (itr != metaMeteringModeMap_.end()) {
160 meteringMode = itr->second;
161 return CameraErrorCode::SUCCESS;
162 }
163 return CameraErrorCode::SUCCESS;
164 // LCOV_EXCL_STOP
165 }
166 // ISO
GetIsoRange(std::vector<int32_t> & isoRange)167 int32_t ProfessionSession::GetIsoRange(std::vector<int32_t> &isoRange)
168 {
169 isoRange.clear();
170 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
171 "ProfessionSession::GetIsoRange Session is not Commited");
172 auto inputDevice = GetInputDevice();
173 CHECK_RETURN_RET_ELOG(!inputDevice, CameraErrorCode::SUCCESS,
174 "ProfessionSession::GetIsoRange camera device is null");
175 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
176 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
177 "ProfessionSession::GetIsoRange camera deviceInfo is null");
178 // Enabling rawImageDelivery implies using raw camera through the YUV profile, Therefore, we need to get raw camera
179 // static metadata rather than get dynamic metadata.
180 bool isNeedPhysicalCameraMeta = isRawImageDelivery_ || photoProfile_.format_ == CAMERA_FORMAT_DNG_XDRAW;
181 auto metadata = isNeedPhysicalCameraMeta ? inputDeviceInfo->GetCachedMetadata() : GetMetadata();
182 CHECK_RETURN_RET_ELOG(metadata == nullptr, CameraErrorCode::INVALID_ARGUMENT, "GetIsoRange metadata is null");
183
184 camera_metadata_item_t item;
185 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_ISO_VALUES, &item);
186 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS || item.count == 0, CameraErrorCode::INVALID_ARGUMENT,
187 "ProfessionSession::GetIsoRange Failed with return code %{public}d", ret);
188 std::vector<std::vector<int32_t> > modeIsoRanges = {};
189 std::vector<int32_t> modeRange = {};
190 for (uint32_t i = 0; i < item.count; i++) {
191 if (item.data.i32[i] != -1) {
192 modeRange.emplace_back(item.data.i32[i]);
193 continue;
194 }
195 MEDIA_DEBUG_LOG("ProfessionSession::GetIsoRange mode %{public}d, range=%{public}s",
196 GetMode(), Container2String(modeRange.begin(), modeRange.end()).c_str());
197 modeIsoRanges.emplace_back(std::move(modeRange));
198 modeRange.clear();
199 }
200
201 for (auto it : modeIsoRanges) {
202 MEDIA_DEBUG_LOG("ProfessionSession::GetIsoRange ranges=%{public}s",
203 Container2String(it.begin(), it.end()).c_str());
204 if (GetMode() == it.at(0)) {
205 isoRange.resize(it.size() - 1);
206 std::copy(it.begin() + 1, it.end(), isoRange.begin());
207 }
208 }
209 MEDIA_INFO_LOG("ProfessionSessionNapi::GetIsoRange isoRange=%{public}s, len = %{public}zu",
210 Container2String(isoRange.begin(), isoRange.end()).c_str(), isoRange.size());
211 return CameraErrorCode::SUCCESS;
212 }
213
SetISO(int32_t iso)214 int32_t ProfessionSession::SetISO(int32_t iso)
215 {
216 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
217 "ProfessionSession::SetISO Session is not Commited");
218 CHECK_RETURN_RET_ELOG(changedMetadata_ == nullptr, CameraErrorCode::SUCCESS,
219 "ProfessionSession::SetISO Need to call LockForControl() before setting camera properties");
220 // LCOV_EXCL_START
221 MEDIA_DEBUG_LOG("ProfessionSession::SetISO iso value: %{public}d", iso);
222 auto inputDevice = GetInputDevice();
223 CHECK_RETURN_RET_ELOG(!inputDevice || !inputDevice->GetCameraDeviceInfo(),
224 CameraErrorCode::SUCCESS, "ProfessionSession::SetISO camera device is null");
225
226 std::vector<int32_t> isoRange;
227 CHECK_RETURN_RET_ELOG((GetIsoRange(isoRange) != CameraErrorCode::SUCCESS) && isoRange.empty(),
228 CameraErrorCode::OPERATION_NOT_ALLOWED, "ProfessionSession::SetISO range is empty");
229
230 const int32_t autoIsoValue = 0;
231 CHECK_RETURN_RET(iso != autoIsoValue && std::find(isoRange.begin(), isoRange.end(), iso) == isoRange.end(),
232 CameraErrorCode::INVALID_ARGUMENT);
233 bool status = AddOrUpdateMetadata(changedMetadata_, OHOS_CONTROL_ISO_VALUE, &iso, 1);
234 CHECK_PRINT_ELOG(!status, "ProfessionSession::SetISO Failed to set exposure compensation");
235 isoValue_ = static_cast<uint32_t>(iso);
236 return CameraErrorCode::SUCCESS;
237 // LCOV_EXCL_STOP
238 }
239
GetISO(int32_t & iso)240 int32_t ProfessionSession::GetISO(int32_t &iso)
241 {
242 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
243 "ProfessionSession::GetISO Session is not Commited");
244 auto inputDevice = GetInputDevice();
245 CHECK_RETURN_RET_ELOG(!inputDevice, CameraErrorCode::INVALID_ARGUMENT,
246 "ProfessionSession::GetISO camera device is null");
247 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
248 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::INVALID_ARGUMENT,
249 "ProfessionSession::GetISO camera device is null");
250 std::shared_ptr<OHOS::Camera::CameraMetadata> metadata = inputDeviceInfo->GetCachedMetadata();
251 camera_metadata_item_t item;
252 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_ISO_VALUE, &item);
253 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS, CameraErrorCode::INVALID_ARGUMENT,
254 "ProfessionSession::GetISO Failed with return code %{public}d", ret);
255 // LCOV_EXCL_START
256 iso = item.data.i32[0];
257 MEDIA_DEBUG_LOG("iso: %{public}d", iso);
258 return CameraErrorCode::SUCCESS;
259 // LCOV_EXCL_STOP
260 }
261
IsManualIsoSupported()262 bool ProfessionSession::IsManualIsoSupported()
263 {
264 CAMERA_SYNC_TRACE;
265 MEDIA_DEBUG_LOG("Enter IsManualIsoSupported");
266
267 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), false,
268 "ProfessionSession::IsManualIsoSupported Session is not Commited");
269
270 auto inputDevice = GetInputDevice();
271 CHECK_RETURN_RET_ELOG(inputDevice == nullptr, false,
272 "ProfessionSession::IsManualIsoSupported camera device is null");
273
274 auto deviceInfo = inputDevice->GetCameraDeviceInfo();
275 CHECK_RETURN_RET_ELOG(deviceInfo == nullptr, false,
276 "ProfessionSession::IsManualIsoSupported camera deviceInfo is null");
277 std::shared_ptr<Camera::CameraMetadata> metadata = deviceInfo->GetCachedMetadata();
278 camera_metadata_item_t item;
279 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_ISO_VALUES, &item);
280 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS || item.count == 0, false,
281 "ProfessionSession::IsMacroSupported Failed with return code %{public}d", ret);
282 return true;
283 }
284
285 // focus mode
GetSupportedFocusModes(std::vector<FocusMode> & supportedFocusModes)286 int32_t ProfessionSession::GetSupportedFocusModes(std::vector<FocusMode> &supportedFocusModes)
287 {
288 supportedFocusModes.clear();
289 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
290 "ProfessionSession::GetSupportedFocusModes Session is not Commited");
291
292 auto inputDevice = GetInputDevice();
293 CHECK_RETURN_RET_ELOG(!inputDevice,
294 CameraErrorCode::SUCCESS, "ProfessionSession::GetSupportedFocusModes camera device is null");
295 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
296 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
297 "ProfessionSession::GetSupportedFocusModes camera deviceInfo is null");
298 sptr<CameraDevice> cameraDevNow = inputDevice->GetCameraDeviceInfo();
299 if (cameraDevNow != nullptr && cameraDevNow->isConcurrentLimted_ == 1) {
300 // LCOV_EXCL_START
301 for (int i = 0; i < cameraDevNow->limtedCapabilitySave_.focusmodes.count;
302 i++) {
303 camera_focus_mode_enum_t num = static_cast<camera_focus_mode_enum_t>(cameraDevNow->
304 limtedCapabilitySave_.focusmodes.mode[i]);
305 auto itr = g_metaFocusModeMap_.find(num);
306 if (itr != g_metaFocusModeMap_.end()) {
307 supportedFocusModes.emplace_back(itr->second);
308 }
309 }
310 return CameraErrorCode::SUCCESS;
311 // LCOV_EXCL_STOP
312 }
313 std::shared_ptr<Camera::CameraMetadata> metadata = inputDeviceInfo->GetCachedMetadata();
314 camera_metadata_item_t item;
315 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FOCUS_MODES, &item);
316 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS, CameraErrorCode::SUCCESS,
317 "ProfessionSession::GetSupportedFocusModes Failed with return code %{public}d", ret);
318 for (uint32_t i = 0; i < item.count; i++) {
319 auto itr = g_metaFocusModeMap_.find(static_cast<camera_focus_mode_enum_t>(item.data.u8[i]));
320 CHECK_EXECUTE(itr != g_metaFocusModeMap_.end(), supportedFocusModes.emplace_back(itr->second));
321 }
322 return CameraErrorCode::SUCCESS;
323 }
324
IsFocusModeSupported(FocusMode focusMode,bool & isSupported)325 int32_t ProfessionSession::IsFocusModeSupported(FocusMode focusMode, bool &isSupported)
326 {
327 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
328 "ProfessionSession::IsFocusModeSupported Session is not Commited");
329 std::vector<FocusMode> vecSupportedMeteringModeList;
330 (void)(this->GetSupportedFocusModes(vecSupportedMeteringModeList));
331 if (find(vecSupportedMeteringModeList.begin(), vecSupportedMeteringModeList.end(),
332 focusMode) != vecSupportedMeteringModeList.end()) {
333 isSupported = true;
334 return CameraErrorCode::SUCCESS;
335 }
336 isSupported = false;
337 return CameraErrorCode::SUCCESS;
338 }
339
SetFocusMode(FocusMode focusMode)340 int32_t ProfessionSession::SetFocusMode(FocusMode focusMode)
341 {
342 CAMERA_SYNC_TRACE;
343 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
344 "ProfessionSession::SetFocusMode Session is not Commited");
345 CHECK_RETURN_RET_ELOG(changedMetadata_ == nullptr, CameraErrorCode::SUCCESS,
346 "ProfessionSession::SetFocusMode Need to call LockForControl() before setting camera properties");
347 // LCOV_EXCL_START
348 uint8_t focus = FOCUS_MODE_LOCKED;
349 auto itr = g_fwkFocusModeMap_.find(focusMode);
350 if (itr == g_fwkFocusModeMap_.end()) {
351 MEDIA_ERR_LOG("ProfessionSession::SetFocusMode Unknown exposure mode");
352 } else {
353 focus = itr->second;
354 }
355 MEDIA_DEBUG_LOG("ProfessionSession::SetFocusMode Focus mode: %{public}d", focusMode);
356 bool status = AddOrUpdateMetadata(changedMetadata_, OHOS_CONTROL_FOCUS_MODE, &focus, 1);
357 CHECK_PRINT_ELOG(!status, "ProfessionSession::SetFocusMode Failed to set focus mode");
358 return CameraErrorCode::SUCCESS;
359 // LCOV_EXCL_STOP
360 }
361
GetFocusMode(FocusMode & focusMode)362 int32_t ProfessionSession::GetFocusMode(FocusMode &focusMode)
363 {
364 focusMode = FOCUS_MODE_MANUAL;
365 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
366 "ProfessionSession::GetFocusMode Session is not Commited");
367 auto inputDevice = GetInputDevice();
368 CHECK_RETURN_RET_ELOG(!inputDevice, CameraErrorCode::SUCCESS,
369 "ProfessionSession::GetFocusMode camera device is null");
370 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
371 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
372 "ProfessionSession::GetFocusMode camera deviceInfo is null");
373 std::shared_ptr<Camera::CameraMetadata> metadata = inputDeviceInfo->GetCachedMetadata();
374 camera_metadata_item_t item;
375 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_FOCUS_MODE, &item);
376 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS, CameraErrorCode::SUCCESS,
377 "ProfessionSession::GetFocusMode Failed with return code %{public}d", ret);
378 // LCOV_EXCL_START
379 auto itr = g_metaFocusModeMap_.find(static_cast<camera_focus_mode_enum_t>(item.data.u8[0]));
380 if (itr != g_metaFocusModeMap_.end()) {
381 focusMode = itr->second;
382 return CameraErrorCode::SUCCESS;
383 }
384 return CameraErrorCode::SUCCESS;
385 // LCOV_EXCL_STOP
386 }
387
388 // Exposure Hint
GetSupportedExposureHintModes(std::vector<ExposureHintMode> & supportedExposureHintModes)389 int32_t ProfessionSession::GetSupportedExposureHintModes(std::vector<ExposureHintMode> &supportedExposureHintModes)
390 {
391 supportedExposureHintModes.clear();
392 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
393 "ProfessionSession::GetSupportedExposureHintModes Session is not Commited");
394 auto inputDevice = GetInputDevice();
395 CHECK_RETURN_RET_ELOG(!inputDevice,
396 CameraErrorCode::SUCCESS,
397 "ProfessionSession::GetSupportedExposureHintModes camera device is null");
398 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
399 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
400 "ProfessionSession::GetSupportedExposureHintModes camera deviceInfo is null");
401 std::shared_ptr<Camera::CameraMetadata> metadata = inputDeviceInfo->GetCachedMetadata();
402 camera_metadata_item_t item;
403 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_EXPOSURE_HINT_SUPPORTED, &item);
404 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS, CameraErrorCode::SUCCESS,
405 "ProfessionSession::GetSupportedExposureHintModes Failed with return code %{public}d", ret);
406 for (uint32_t i = 0; i < item.count; i++) {
407 auto itr = metaExposureHintModeMap_.find(static_cast<camera_exposure_hint_mode_enum_t>(item.data.u8[i]));
408 CHECK_EXECUTE(itr != metaExposureHintModeMap_.end(), supportedExposureHintModes.emplace_back(itr->second));
409 }
410 return CameraErrorCode::SUCCESS;
411 }
412
SetExposureHintMode(ExposureHintMode mode)413 int32_t ProfessionSession::SetExposureHintMode(ExposureHintMode mode)
414 {
415 CAMERA_SYNC_TRACE;
416 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
417 "ProfessionSession::SetExposureHintMode Session is not Commited");
418 CHECK_RETURN_RET_ELOG(changedMetadata_ == nullptr, CameraErrorCode::SUCCESS,
419 "ProfessionSession::SetExposureHintMode Need to call LockForControl() before setting camera properties");
420 // LCOV_EXCL_START
421 uint8_t exposureHintMode = OHOS_CAMERA_EXPOSURE_HINT_UNSUPPORTED;
422 auto itr = fwkExposureHintModeMap_.find(mode);
423 if (itr == fwkExposureHintModeMap_.end()) {
424 MEDIA_ERR_LOG("ProfessionSession::SetExposureHintMode Unknown mode");
425 } else {
426 exposureHintMode = itr->second;
427 }
428 MEDIA_DEBUG_LOG("ProfessionSession::SetExposureHintMode ExposureHint mode: %{public}d", exposureHintMode);
429 bool status = AddOrUpdateMetadata(changedMetadata_, OHOS_CONTROL_EXPOSURE_HINT_MODE, &exposureHintMode, 1);
430 CHECK_PRINT_ELOG(!status, "ProfessionSession::SetExposureHintMode Failed to set ExposureHint mode");
431 return CameraErrorCode::SUCCESS;
432 // LCOV_EXCL_STOP
433 }
434
GetExposureHintMode(ExposureHintMode & mode)435 int32_t ProfessionSession::GetExposureHintMode(ExposureHintMode &mode)
436 {
437 mode = EXPOSURE_HINT_UNSUPPORTED;
438 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
439 "ProfessionSession::GetExposureHintMode Session is not Commited");
440 auto inputDevice = GetInputDevice();
441 CHECK_RETURN_RET_ELOG(!inputDevice, CameraErrorCode::SUCCESS,
442 "ProfessionSession::GetExposureHintMode camera device is null");
443 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
444 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
445 "ProfessionSession::GetExposureHintMode camera device is null");
446 std::shared_ptr<Camera::CameraMetadata> metadata = inputDeviceInfo->GetCachedMetadata();
447 camera_metadata_item_t item;
448 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_EXPOSURE_HINT_MODE, &item);
449 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS, CameraErrorCode::SUCCESS,
450 "ProfessionSession::GetExposureHintMode Failed with return code %{public}d", ret);
451 // LCOV_EXCL_START
452 auto itr = metaExposureHintModeMap_.find(static_cast<camera_exposure_hint_mode_enum_t>(item.data.u8[0]));
453 if (itr != metaExposureHintModeMap_.end()) {
454 mode = itr->second;
455 return CameraErrorCode::SUCCESS;
456 }
457 return CameraErrorCode::SUCCESS;
458 // LCOV_EXCL_STOP
459 }
460 // Focus Flash Assist
GetSupportedFocusAssistFlashModes(std::vector<FocusAssistFlashMode> & supportedFocusAssistFlashModes)461 int32_t ProfessionSession::GetSupportedFocusAssistFlashModes(
462 std::vector<FocusAssistFlashMode> &supportedFocusAssistFlashModes)
463 {
464 supportedFocusAssistFlashModes.clear();
465 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
466 "ProfessionSession::GetSupportedFocusAssistFlashModes Session is not Commited");
467 auto inputDevice = GetInputDevice();
468 CHECK_RETURN_RET_ELOG(!inputDevice, CameraErrorCode::SUCCESS,
469 "ProfessionSession::GetSupportedFocusAssistFlashModes camera device is null");
470 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
471 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
472 "ProfessionSession::GetSupportedFocusAssistFlashModes camera deviceInfo is null");
473 std::shared_ptr<Camera::CameraMetadata> metadata = inputDeviceInfo->GetCachedMetadata();
474 camera_metadata_item_t item;
475 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FOCUS_ASSIST_FLASH_SUPPORTED_MODES, &item);
476 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS, CameraErrorCode::SUCCESS,
477 "ProfessionSession::GetSupportedFocusAssistFlashModes Failed with return code %{public}d", ret);
478 for (uint32_t i = 0; i < item.count; i++) {
479 auto itr = metaFocusAssistFlashModeMap_.find(
480 static_cast<camera_focus_assist_flash_mode_enum_t>(item.data.u8[i]));
481 CHECK_EXECUTE(itr != metaFocusAssistFlashModeMap_.end(),
482 supportedFocusAssistFlashModes.emplace_back(itr->second));
483 }
484 return CameraErrorCode::SUCCESS;
485 }
486
IsFocusAssistFlashModeSupported(FocusAssistFlashMode mode,bool & isSupported)487 int32_t ProfessionSession::IsFocusAssistFlashModeSupported(FocusAssistFlashMode mode, bool &isSupported)
488 {
489 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
490 "ProfessionSession::IsFocusAssistFlashModeSupported Session is not Commited");
491 std::vector<FocusAssistFlashMode> vecSupportedFocusAssistFlashModeList;
492 (void)this->GetSupportedFocusAssistFlashModes(vecSupportedFocusAssistFlashModeList);
493 if (find(vecSupportedFocusAssistFlashModeList.begin(), vecSupportedFocusAssistFlashModeList.end(),
494 mode) != vecSupportedFocusAssistFlashModeList.end()) {
495 isSupported = true;
496 return CameraErrorCode::SUCCESS;
497 }
498 isSupported = false;
499 return CameraErrorCode::SUCCESS;
500 }
501
SetFocusAssistFlashMode(FocusAssistFlashMode mode)502 int32_t ProfessionSession::SetFocusAssistFlashMode(FocusAssistFlashMode mode)
503 {
504 CAMERA_SYNC_TRACE;
505 MEDIA_DEBUG_LOG("ProfessionSession::SetFocusAssistFlashMode app mode: %{public}d", static_cast<int32_t>(mode));
506 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
507 "ProfessionSession::IsFocusAssistFlashModeSupported Session is not Commited");
508 CHECK_RETURN_RET_ELOG(changedMetadata_ == nullptr, CameraErrorCode::SUCCESS,
509 "ProfessionSession::IsFocusAssistFlashModeSupported Need to call LockForControl "
510 "before setting camera properties");
511 // LCOV_EXCL_START
512 uint8_t value = OHOS_CAMERA_FOCUS_ASSIST_FLASH_MODE_DEFAULT;
513 auto itr = fwkFocusAssistFlashModeMap_.find(mode);
514 if (itr == fwkFocusAssistFlashModeMap_.end()) {
515 MEDIA_ERR_LOG("ProfessionSession::SetFocusAssistFlashMode Unknown exposure mode");
516 } else {
517 value = itr->second;
518 }
519 MEDIA_DEBUG_LOG("ProfessionSession::SetFocusAssistFlashMode FocusAssistFlash mode: %{public}d", value);
520 bool status = AddOrUpdateMetadata(changedMetadata_, OHOS_CONTROL_FOCUS_ASSIST_FLASH_SUPPORTED_MODE, &value, 1);
521 CHECK_PRINT_ELOG(!status, "ProfessionSession::SetFocusAssistFlashMode Failed to set FocusAssistFlash mode");
522 return CameraErrorCode::SUCCESS;
523 // LCOV_EXCL_STOP
524 }
525
GetFocusAssistFlashMode(FocusAssistFlashMode & mode)526 int32_t ProfessionSession::GetFocusAssistFlashMode(FocusAssistFlashMode &mode)
527 {
528 mode = FOCUS_ASSIST_FLASH_MODE_DEFAULT;
529 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
530 "ProfessionSession::GetFocusAssistFlashMode Session is not Commited");
531 auto inputDevice = GetInputDevice();
532 CHECK_RETURN_RET_ELOG(!inputDevice, CameraErrorCode::SUCCESS,
533 "ProfessionSession::GetFocusAssistFlashMode camera device is null");
534 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
535 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
536 "ProfessionSession::GetFocusAssistFlashMode camera deviceInfo is null");
537 std::shared_ptr<Camera::CameraMetadata> metadata = inputDeviceInfo->GetCachedMetadata();
538 camera_metadata_item_t item;
539 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_FOCUS_ASSIST_FLASH_SUPPORTED_MODE, &item);
540 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS, CameraErrorCode::SUCCESS,
541 "ProfessionSession::GetFocusAssistFlashMode Failed with return code %{public}d", ret);
542 // LCOV_EXCL_START
543 auto itr = metaFocusAssistFlashModeMap_.find(static_cast<camera_focus_assist_flash_mode_enum_t>(item.data.u8[0]));
544 if (itr != metaFocusAssistFlashModeMap_.end()) {
545 mode = itr->second;
546 return CameraErrorCode::SUCCESS;
547 }
548 return CameraErrorCode::SUCCESS;
549 // LCOV_EXCL_STOP
550 }
551
552 // flash mode
GetSupportedFlashModes(std::vector<FlashMode> & supportedFlashModes)553 int32_t ProfessionSession::GetSupportedFlashModes(std::vector<FlashMode> &supportedFlashModes)
554 {
555 // LCOV_EXCL_START
556 supportedFlashModes.clear();
557 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
558 "ProfessionSession::GetSupportedFlashModes Session is not Commited");
559 auto inputDevice = GetInputDevice();
560 CHECK_RETURN_RET_ELOG(!inputDevice, CameraErrorCode::SUCCESS,
561 "ProfessionSession::GetSupportedFlashModes camera device is null");
562 sptr<CameraDevice> cameraDevNow = inputDevice->GetCameraDeviceInfo();
563 if (cameraDevNow != nullptr && cameraDevNow->isConcurrentLimted_ == 1) {
564 for (int i = 0; i < cameraDevNow->limtedCapabilitySave_.flashmodes.count;
565 i++) {
566 camera_flash_mode_enum_t num = static_cast<camera_flash_mode_enum_t>(cameraDevNow->
567 limtedCapabilitySave_.flashmodes.mode[i]);
568 auto it = g_metaFlashModeMap_.find(num);
569 if (it != g_metaFlashModeMap_.end()) {
570 supportedFlashModes.emplace_back(it->second);
571 }
572 }
573 return CameraErrorCode::SUCCESS;
574 }
575 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
576 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
577 "ProfessionSession::GetSupportedFlashModes camera deviceInfo is null");
578 auto metadata = isRawImageDelivery_ ? GetMetadata() : inputDeviceInfo->GetCachedMetadata();
579 camera_metadata_item_t item;
580 CHECK_RETURN_RET_ELOG(
581 !metadata, CameraErrorCode::SUCCESS, "ProfessionSession::GetSupportedFlashModes metadata is nullptr");
582 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_FLASH_MODES, &item);
583 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS, CameraErrorCode::SUCCESS,
584 "ProfessionSession::GetSupportedFlashModes Failed with return code %{public}d", ret);
585 g_transformValidData(item, g_metaFlashModeMap_, supportedFlashModes);
586 return CameraErrorCode::SUCCESS;
587 // LCOV_EXCL_STOP
588 }
589
GetFlashMode(FlashMode & flashMode)590 int32_t ProfessionSession::GetFlashMode(FlashMode &flashMode)
591 {
592 // LCOV_EXCL_START
593 flashMode = FLASH_MODE_CLOSE;
594 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
595 "ProfessionSession::GetFlashMode Session is not Commited");
596 auto inputDevice = GetInputDevice();
597 CHECK_RETURN_RET_ELOG(!inputDevice, CameraErrorCode::SUCCESS,
598 "ProfessionSession::GetFlashMode camera device is null");
599 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
600 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
601 "ProfessionSession::GetFlashMode camera deviceInfo is null");
602 auto metadata = isRawImageDelivery_ ? GetMetadata() : inputDeviceInfo->GetCachedMetadata();
603 camera_metadata_item_t item;
604 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_FLASH_MODE, &item);
605 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS, CameraErrorCode::SUCCESS,
606 "ProfessionSession::GetFlashMode Failed with return code %{public}d", ret);
607 auto itr = g_metaFlashModeMap_.find(static_cast<camera_flash_mode_enum_t>(item.data.u8[0]));
608 if (itr != g_metaFlashModeMap_.end()) {
609 flashMode = itr->second;
610 return CameraErrorCode::SUCCESS;
611 }
612
613 return CameraErrorCode::SUCCESS;
614 // LCOV_EXCL_STOP
615 }
616
SetFlashMode(FlashMode flashMode)617 int32_t ProfessionSession::SetFlashMode(FlashMode flashMode)
618 {
619 // LCOV_EXCL_START
620 CAMERA_SYNC_TRACE;
621 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
622 "ProfessionSession::SetFlashMode Session is not Commited");
623 CHECK_RETURN_RET_ELOG(changedMetadata_ == nullptr, CameraErrorCode::SUCCESS,
624 "ProfessionSession::SetFlashMode Need to call LockForControl() before setting camera properties");
625 MEDIA_INFO_LOG("ProfessionSession::SetFlashMode flashMode:%{public}d", flashMode);
626 uint8_t flash = g_fwkFlashModeMap_.at(FLASH_MODE_CLOSE);
627 auto itr = g_fwkFlashModeMap_.find(flashMode);
628 if (itr == g_fwkFlashModeMap_.end()) {
629 MEDIA_ERR_LOG("ProfessionSession::SetFlashMode Unknown exposure mode");
630 } else {
631 flash = itr->second;
632 }
633 bool status = AddOrUpdateMetadata(changedMetadata_, OHOS_CONTROL_FLASH_MODE, &flash, 1);
634 CHECK_PRINT_ELOG(!status, "ProfessionSession::SetFlashMode Failed to set flash mode");
635 return CameraErrorCode::SUCCESS;
636 // LCOV_EXCL_STOP
637 }
638
IsFlashModeSupported(FlashMode flashMode,bool & isSupported)639 int32_t ProfessionSession::IsFlashModeSupported(FlashMode flashMode, bool &isSupported)
640 {
641 // LCOV_EXCL_START
642 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
643 "ProfessionSession::IsFlashModeSupported Session is not Commited");
644 std::vector<FlashMode> vecSupportedFlashModeList;
645 (void)this->GetSupportedFlashModes(vecSupportedFlashModeList);
646 if (find(vecSupportedFlashModeList.begin(), vecSupportedFlashModeList.end(), flashMode) !=
647 vecSupportedFlashModeList.end()) {
648 isSupported = true;
649 return CameraErrorCode::SUCCESS;
650 }
651 isSupported = false;
652 return CameraErrorCode::SUCCESS;
653 // LCOV_EXCL_STOP
654 }
655
HasFlash(bool & hasFlash)656 int32_t ProfessionSession::HasFlash(bool &hasFlash)
657 {
658 // LCOV_EXCL_START
659 hasFlash = false;
660 CHECK_RETURN_RET_ELOG(!IsSessionCommited(), CameraErrorCode::SESSION_NOT_CONFIG,
661 "ProfessionSession::HasFlash Session is not Commited");
662 std::vector<FlashMode> supportedFlashModeList;
663 GetSupportedFlashModes(supportedFlashModeList);
664 bool onlyHasCloseMode = supportedFlashModeList.size() == 1 && supportedFlashModeList[0] == FLASH_MODE_CLOSE;
665 if (!supportedFlashModeList.empty() && !onlyHasCloseMode) {
666 hasFlash = true;
667 }
668 return CameraErrorCode::SUCCESS;
669 // LCOV_EXCL_STOP
670 }
671 // XMAGE
672
GetSupportedColorEffects(std::vector<ColorEffect> & supportedColorEffects)673 int32_t ProfessionSession::GetSupportedColorEffects(std::vector<ColorEffect>& supportedColorEffects)
674 {
675 supportedColorEffects.clear();
676 CHECK_RETURN_RET_ELOG(!(IsSessionCommited() || IsSessionConfiged()), CameraErrorCode::SESSION_NOT_CONFIG,
677 "ProfessionSession::GetSupportedColorEffects Session is not Commited");
678 auto inputDevice = GetInputDevice();
679 CHECK_RETURN_RET_ELOG(!inputDevice, CameraErrorCode::SUCCESS,
680 "ProfessionSession::GetSupportedColorEffects camera device is null");
681 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
682 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
683 "ProfessionSession::GetSupportedColorEffects camera deviceInfo is null");
684 std::shared_ptr<Camera::CameraMetadata> metadata = inputDeviceInfo->GetCachedMetadata();
685 camera_metadata_item_t item;
686 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_ABILITY_SUPPORTED_COLOR_MODES, &item);
687 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS, CameraErrorCode::SUCCESS,
688 "ProfessionSession::GetSupportedColorEffects Failed with return code %{public}d", ret);
689 for (uint32_t i = 0; i < item.count; i++) {
690 auto itr = g_metaColorEffectMap_.find(static_cast<camera_xmage_color_type_t>(item.data.u8[i]));
691 CHECK_EXECUTE(itr != g_metaColorEffectMap_.end(), supportedColorEffects.emplace_back(itr->second));
692 }
693 return CameraErrorCode::SUCCESS;
694 }
695
GetColorEffect(ColorEffect & colorEffect)696 int32_t ProfessionSession::GetColorEffect(ColorEffect& colorEffect)
697 {
698 colorEffect = ColorEffect::COLOR_EFFECT_NORMAL;
699 CHECK_RETURN_RET_ELOG(!(IsSessionCommited() || IsSessionConfiged()), CameraErrorCode::SESSION_NOT_CONFIG,
700 "ProfessionSession::GetColorEffect Session is not Commited");
701 auto inputDevice = GetInputDevice();
702 CHECK_RETURN_RET_ELOG(!inputDevice, CameraErrorCode::SUCCESS,
703 "ProfessionSession::GetColorEffect camera device is null");
704 auto inputDeviceInfo = inputDevice->GetCameraDeviceInfo();
705 CHECK_RETURN_RET_ELOG(!inputDeviceInfo, CameraErrorCode::SUCCESS,
706 "ProfessionSession::GetColorEffect camera deviceInfo is null");
707 std::shared_ptr<Camera::CameraMetadata> metadata = inputDeviceInfo->GetCachedMetadata();
708 camera_metadata_item_t item;
709 int ret = Camera::FindCameraMetadataItem(metadata->get(), OHOS_CONTROL_SUPPORTED_COLOR_MODES, &item);
710 CHECK_RETURN_RET_ELOG(ret != CAM_META_SUCCESS || item.count == 0, CameraErrorCode::SUCCESS,
711 "ProfessionSession::GetColorEffect Failed with return code %{public}d", ret);
712 // LCOV_EXCL_START
713 auto itr = g_metaColorEffectMap_.find(static_cast<camera_xmage_color_type_t>(item.data.u8[0]));
714 if (itr != g_metaColorEffectMap_.end()) {
715 colorEffect = itr->second;
716 }
717 return CameraErrorCode::SUCCESS;
718 // LCOV_EXCL_STOP
719 }
720
SetColorEffect(ColorEffect colorEffect)721 int32_t ProfessionSession::SetColorEffect(ColorEffect colorEffect)
722 {
723 CAMERA_SYNC_TRACE;
724 CHECK_RETURN_RET_ELOG(!(IsSessionCommited() || IsSessionConfiged()), CameraErrorCode::SESSION_NOT_CONFIG,
725 "ProfessionSession::GetColorEffect Session is not Commited");
726 CHECK_RETURN_RET_ELOG(changedMetadata_ == nullptr, CameraErrorCode::SUCCESS,
727 "ProfessionSession::SetFlashMode Need to call LockForControl() before setting camera properties");
728 // LCOV_EXCL_START
729 uint8_t colorEffectTemp = ColorEffect::COLOR_EFFECT_NORMAL;
730 auto itr = g_fwkColorEffectMap_.find(colorEffect);
731 if (itr == g_fwkColorEffectMap_.end()) {
732 MEDIA_ERR_LOG("ProfessionSession::SetColorEffect unknown is color effect");
733 } else {
734 colorEffectTemp = itr->second;
735 }
736 MEDIA_DEBUG_LOG("ProfessionSession::SetColorEffect: %{public}d", colorEffect);
737 bool status = AddOrUpdateMetadata(changedMetadata_, OHOS_CONTROL_SUPPORTED_COLOR_MODES, &colorEffectTemp, 1);
738 CHECK_PRINT_ELOG(!status, "ProfessionSession::SetColorEffect Failed to set color effect");
739 return CameraErrorCode::SUCCESS;
740 // LCOV_EXCL_STOP
741 }
742
CanAddOutput(sptr<CaptureOutput> & output)743 bool ProfessionSession::CanAddOutput(sptr<CaptureOutput> &output)
744 {
745 CAMERA_SYNC_TRACE;
746 MEDIA_DEBUG_LOG("Enter Into ProfessionSession::CanAddOutput");
747 CHECK_RETURN_RET_ELOG(!IsSessionConfiged() || output == nullptr, false,
748 "ProfessionSession::CanAddOutput operation is Not allowed!");
749 return CaptureSession::CanAddOutput(output);
750 }
751
752 //callbacks
SetExposureInfoCallback(std::shared_ptr<ExposureInfoCallback> callback)753 void ProfessionSession::SetExposureInfoCallback(std::shared_ptr<ExposureInfoCallback> callback)
754 {
755 // LCOV_EXCL_START
756 std::lock_guard<std::mutex> lock(sessionCallbackMutex_);
757 exposureInfoCallback_ = callback;
758 // LCOV_EXCL_STOP
759 }
760
SetIsoInfoCallback(std::shared_ptr<IsoInfoCallback> callback)761 void ProfessionSession::SetIsoInfoCallback(std::shared_ptr<IsoInfoCallback> callback)
762 {
763 // LCOV_EXCL_START
764 std::lock_guard<std::mutex> lock(sessionCallbackMutex_);
765 isoInfoCallback_ = callback;
766 // LCOV_EXCL_STOP
767 }
768
SetApertureInfoCallback(std::shared_ptr<ApertureInfoCallback> callback)769 void ProfessionSession::SetApertureInfoCallback(std::shared_ptr<ApertureInfoCallback> callback)
770 {
771 // LCOV_EXCL_START
772 std::lock_guard<std::mutex> lock(sessionCallbackMutex_);
773 apertureInfoCallback_ = callback;
774 // LCOV_EXCL_STOP
775 }
776
SetLuminationInfoCallback(std::shared_ptr<LuminationInfoCallback> callback)777 void ProfessionSession::SetLuminationInfoCallback(std::shared_ptr<LuminationInfoCallback> callback)
778 {
779 // LCOV_EXCL_START
780 std::lock_guard<std::mutex> lock(sessionCallbackMutex_);
781 luminationInfoCallback_ = callback;
782 // LCOV_EXCL_STOP
783 }
784
ProcessSensorExposureTimeChange(const std::shared_ptr<OHOS::Camera::CameraMetadata> & result)785 void ProfessionSession::ProcessSensorExposureTimeChange(const std::shared_ptr<OHOS::Camera::CameraMetadata> &result)
786 {
787 // LCOV_EXCL_START
788 camera_metadata_item_t item;
789 common_metadata_header_t* metadata = result->get();
790 int ret = Camera::FindCameraMetadataItem(metadata, OHOS_STATUS_SENSOR_EXPOSURE_TIME, &item);
791 if (ret == CAM_META_SUCCESS) {
792 int32_t numerator = item.data.r->numerator;
793 int32_t denominator = item.data.r->denominator;
794 MEDIA_DEBUG_LOG("SensorExposureTime: %{public}d/%{public}d", numerator, denominator);
795 CHECK_RETURN_ELOG(denominator == 0, "ProcessSensorExposureTimeChange error! divide by zero");
796 constexpr int32_t timeUnit = 1000000;
797 uint32_t value = static_cast<uint32_t>(numerator / (denominator / timeUnit));
798 MEDIA_DEBUG_LOG("SensorExposureTime: %{public}d", value);
799 ExposureInfo info = {
800 .exposureDurationValue = value,
801 };
802 std::lock_guard<std::mutex> lock(sessionCallbackMutex_);
803 if (exposureInfoCallback_ != nullptr && (value != exposureDurationValue_)) {
804 exposureInfoCallback_->OnExposureInfoChanged(info);
805 exposureDurationValue_ = value;
806 }
807 }
808 // LCOV_EXCL_STOP
809 }
810
ProcessIsoChange(const std::shared_ptr<OHOS::Camera::CameraMetadata> & result)811 void ProfessionSession::ProcessIsoChange(const std::shared_ptr<OHOS::Camera::CameraMetadata> &result)
812 {
813 // LCOV_EXCL_START
814 camera_metadata_item_t item;
815 common_metadata_header_t* metadata = result->get();
816 int ret = Camera::FindCameraMetadataItem(metadata, OHOS_STATUS_ISO_VALUE, &item);
817 if (ret == CAM_META_SUCCESS) {
818 MEDIA_DEBUG_LOG("Iso Value: %{public}d", item.data.ui32[0]);
819 IsoInfo info = {
820 .isoValue = item.data.ui32[0],
821 };
822 std::lock_guard<std::mutex> lock(sessionCallbackMutex_);
823 if (isoInfoCallback_ != nullptr && item.data.ui32[0] != isoValue_) {
824 CHECK_EXECUTE(isoValue_ != 0, isoInfoCallback_->OnIsoInfoChanged(info));
825 isoValue_ = item.data.ui32[0];
826 }
827 }
828 // LCOV_EXCL_STOP
829 }
830
ProcessApertureChange(const std::shared_ptr<OHOS::Camera::CameraMetadata> & result)831 void ProfessionSession::ProcessApertureChange(const std::shared_ptr<OHOS::Camera::CameraMetadata> &result)
832 {
833 // LCOV_EXCL_START
834 camera_metadata_item_t item;
835 common_metadata_header_t* metadata = result->get();
836 int ret = Camera::FindCameraMetadataItem(metadata, OHOS_STATUS_CAMERA_APERTURE_VALUE, &item);
837 if (ret == CAM_META_SUCCESS) {
838 MEDIA_DEBUG_LOG("aperture Value: %{public}f", ConfusingNumber(item.data.f[0]));
839 std::lock_guard<std::mutex> lock(sessionCallbackMutex_);
840 ApertureInfo info = {
841 .apertureValue = item.data.f[0],
842 };
843 if (apertureInfoCallback_ != nullptr && (item.data.f[0] != apertureValue_ || apertureValue_ == 0)) {
844 apertureInfoCallback_->OnApertureInfoChanged(info);
845 apertureValue_ = item.data.f[0];
846 }
847 }
848 // LCOV_EXCL_STOP
849 }
850
ProcessLuminationChange(const std::shared_ptr<OHOS::Camera::CameraMetadata> & result)851 void ProfessionSession::ProcessLuminationChange(const std::shared_ptr<OHOS::Camera::CameraMetadata> &result)
852 {
853 // LCOV_EXCL_START
854 constexpr float normalizedMeanValue = 255.0;
855 camera_metadata_item_t item;
856 common_metadata_header_t* metadata = result->get();
857 int ret = Camera::FindCameraMetadataItem(metadata, OHOS_STATUS_ALGO_MEAN_Y, &item);
858 float value = item.data.ui32[0] / normalizedMeanValue;
859 if (ret == CAM_META_SUCCESS) {
860 MEDIA_DEBUG_LOG("Lumination Value: %{public}f", value);
861 LuminationInfo info = {
862 .luminationValue = value,
863 };
864 std::lock_guard<std::mutex> lock(sessionCallbackMutex_);
865 if (luminationInfoCallback_ != nullptr && value != luminationValue_) {
866 luminationInfoCallback_->OnLuminationInfoChanged(info);
867 luminationValue_ = value;
868 }
869 }
870 // LCOV_EXCL_STOP
871 }
872
ProcessPhysicalCameraSwitch(const std::shared_ptr<OHOS::Camera::CameraMetadata> & result)873 void ProfessionSession::ProcessPhysicalCameraSwitch(const std::shared_ptr<OHOS::Camera::CameraMetadata>& result)
874 {
875 // LCOV_EXCL_START
876 camera_metadata_item_t item;
877 common_metadata_header_t* metadata = result->get();
878 int ret = Camera::FindCameraMetadataItem(metadata, OHOS_STATUS_PREVIEW_PHYSICAL_CAMERA_ID, &item);
879 CHECK_RETURN(ret != CAM_META_SUCCESS);
880 if (physicalCameraId_ != item.data.u8[0]) {
881 MEDIA_DEBUG_LOG("physicalCameraId: %{public}d", item.data.u8[0]);
882 physicalCameraId_ = item.data.u8[0];
883 ExecuteAbilityChangeCallback();
884 }
885 // LCOV_EXCL_STOP
886 }
887
GetMetadata()888 std::shared_ptr<OHOS::Camera::CameraMetadata> ProfessionSession::GetMetadata()
889 {
890 // LCOV_EXCL_START
891 std::string phyCameraId = std::to_string(physicalCameraId_.load());
892 auto physicalCameraDevice =
893 std::find_if(supportedDevices_.begin(), supportedDevices_.end(), [phyCameraId](const auto& device) -> bool {
894 std::string cameraId = device->GetID();
895 size_t delimPos = cameraId.find("/");
896 CHECK_RETURN_RET(delimPos == std::string::npos, false);
897 string id = cameraId.substr(delimPos + 1);
898 return id.compare(phyCameraId) == 0;
899 });
900 // DELIVERY_PHOTO for default when commit
901 if (physicalCameraDevice != supportedDevices_.end()) {
902 MEDIA_DEBUG_LOG("ProfessionSession::GetMetadata physicalCameraId: device/%{public}s", phyCameraId.c_str());
903 if ((*physicalCameraDevice)->GetCameraType() == CAMERA_TYPE_WIDE_ANGLE && !isRawImageDelivery_) {
904 auto inputDevice = GetInputDevice();
905 CHECK_RETURN_RET(inputDevice == nullptr,
906 std::make_shared<OHOS::Camera::CameraMetadata>(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH));
907 auto info = inputDevice->GetCameraDeviceInfo();
908 CHECK_RETURN_RET(
909 info == nullptr, std::make_shared<OHOS::Camera::CameraMetadata>(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH));
910 MEDIA_DEBUG_LOG("ProfessionSession::GetMetadata using main sensor: %{public}s", info->GetID().c_str());
911 return info->GetCachedMetadata();
912 }
913 if ((*physicalCameraDevice)->GetCachedMetadata() == nullptr) {
914 GetMetadataFromService(*physicalCameraDevice);
915 }
916 return (*physicalCameraDevice)->GetCachedMetadata();
917 }
918 auto inputDevice = GetInputDevice();
919 CHECK_RETURN_RET(
920 inputDevice == nullptr, std::make_shared<OHOS::Camera::CameraMetadata>(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH));
921 auto cameraObj = inputDevice->GetCameraDeviceInfo();
922 CHECK_RETURN_RET(!cameraObj, std::make_shared<OHOS::Camera::CameraMetadata>(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH));
923 MEDIA_DEBUG_LOG("ProfessionSession::GetMetadata no physicalCamera, using current camera device:%{public}s",
924 cameraObj->GetID().c_str());
925 return cameraObj->GetCachedMetadata();
926 // LCOV_EXCL_STOP
927 }
928
ProcessCallbacks(const uint64_t timestamp,const std::shared_ptr<OHOS::Camera::CameraMetadata> & result)929 void ProfessionSession::ProfessionSessionMetadataResultProcessor::ProcessCallbacks(
930 const uint64_t timestamp, const std::shared_ptr<OHOS::Camera::CameraMetadata>& result)
931 {
932 // LCOV_EXCL_START
933 auto session = session_.promote();
934 CHECK_RETURN_ELOG(session == nullptr,
935 "CaptureSession::ProfessionSessionMetadataResultProcessor ProcessCallbacks but session is null");
936
937 session->ProcessAutoFocusUpdates(result);
938 session->ProcessSensorExposureTimeChange(result);
939 session->ProcessIsoChange(result);
940 session->ProcessApertureChange(result);
941 session->ProcessLuminationChange(result);
942 session->ProcessPhysicalCameraSwitch(result);
943 // LCOV_EXCL_STOP
944 }
945 } // CameraStandard
946 } // OHOS
947