1 /*
2 * Copyright (c) 2023-2025 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 "basic_definitions.h"
17
18 #include "dp_log.h"
19
20 namespace OHOS {
21 namespace CameraStandard {
22 namespace DeferredProcessing {
MapDpsErrorCode(DpsError errorCode)23 ErrorCode MapDpsErrorCode(DpsError errorCode)
24 {
25 ErrorCode code = ErrorCode::ERROR_IMAGE_PROC_ABNORMAL;
26 switch (errorCode) {
27 case DpsError::DPS_ERROR_SESSION_SYNC_NEEDED:
28 code = ErrorCode::ERROR_SESSION_SYNC_NEEDED;
29 break;
30 case DpsError::DPS_ERROR_SESSION_NOT_READY_TEMPORARILY:
31 code = ErrorCode::ERROR_SESSION_NOT_READY_TEMPORARILY;
32 break;
33 case DpsError::DPS_ERROR_IMAGE_PROC_INVALID_PHOTO_ID:
34 code = ErrorCode::ERROR_IMAGE_PROC_INVALID_PHOTO_ID;
35 break;
36 case DpsError::DPS_ERROR_IMAGE_PROC_FAILED:
37 code = ErrorCode::ERROR_IMAGE_PROC_FAILED;
38 break;
39 case DpsError::DPS_ERROR_IMAGE_PROC_TIMEOUT:
40 code = ErrorCode::ERROR_IMAGE_PROC_TIMEOUT;
41 break;
42 case DpsError::DPS_ERROR_IMAGE_PROC_ABNORMAL:
43 code = ErrorCode::ERROR_IMAGE_PROC_ABNORMAL;
44 break;
45 case DpsError::DPS_ERROR_IMAGE_PROC_INTERRUPTED:
46 code = ErrorCode::ERROR_IMAGE_PROC_INTERRUPTED;
47 break;
48 case DpsError::DPS_ERROR_VIDEO_PROC_INVALID_VIDEO_ID:
49 code = ErrorCode::ERROR_VIDEO_PROC_INVALID_VIDEO_ID;
50 break;
51 case DpsError::DPS_ERROR_VIDEO_PROC_FAILED:
52 code = ErrorCode::ERROR_VIDEO_PROC_FAILED;
53 break;
54 case DpsError::DPS_ERROR_VIDEO_PROC_TIMEOUT:
55 code = ErrorCode::ERROR_VIDEO_PROC_TIMEOUT;
56 break;
57 case DpsError::DPS_ERROR_VIDEO_PROC_INTERRUPTED:
58 code = ErrorCode::ERROR_VIDEO_PROC_INTERRUPTED;
59 break;
60 default:
61 DP_WARNING_LOG("unexpected error code: %{public}d", errorCode);
62 break;
63 }
64 return code;
65 }
66
MapDpsStatus(DpsStatus statusCode)67 StatusCode MapDpsStatus(DpsStatus statusCode)
68 {
69 StatusCode code = StatusCode::SESSION_STATE_IDLE;
70 switch (statusCode) {
71 case DpsStatus::DPS_SESSION_STATE_IDLE:
72 code = StatusCode::SESSION_STATE_IDLE;
73 break;
74 case DpsStatus::DPS_SESSION_STATE_RUNNABLE:
75 code = StatusCode::SESSION_STATE_RUNNALBE;
76 break;
77 case DpsStatus::DPS_SESSION_STATE_RUNNING:
78 code = StatusCode::SESSION_STATE_RUNNING;
79 break;
80 case DpsStatus::DPS_SESSION_STATE_SUSPENDED:
81 code = StatusCode::SESSION_STATE_SUSPENDED;
82 break;
83 case DpsStatus::DPS_SESSION_STATE_PREEMPTED:
84 code = StatusCode::SESSION_STATE_PREEMPTED;
85 break;
86 default:
87 DP_WARNING_LOG("unexpected error code: %{public}d", statusCode);
88 break;
89 }
90 return code;
91 }
92
MapHdiError(OHOS::HDI::Camera::V1_2::ErrorCode errorCode)93 DpsError MapHdiError(OHOS::HDI::Camera::V1_2::ErrorCode errorCode)
94 {
95 DpsError code = DpsError::DPS_ERROR_IMAGE_PROC_ABNORMAL;
96 switch (errorCode) {
97 case OHOS::HDI::Camera::V1_2::ErrorCode::ERROR_INVALID_ID:
98 code = DpsError::DPS_ERROR_IMAGE_PROC_INVALID_PHOTO_ID;
99 break;
100 case OHOS::HDI::Camera::V1_2::ErrorCode::ERROR_PROCESS:
101 code = DpsError::DPS_ERROR_IMAGE_PROC_FAILED;
102 break;
103 case OHOS::HDI::Camera::V1_2::ErrorCode::ERROR_TIMEOUT:
104 code = DpsError::DPS_ERROR_IMAGE_PROC_TIMEOUT;
105 break;
106 case OHOS::HDI::Camera::V1_2::ErrorCode::ERROR_HIGH_TEMPERATURE:
107 code = DpsError::DPS_ERROR_IMAGE_PROC_HIGH_TEMPERATURE;
108 break;
109 case OHOS::HDI::Camera::V1_2::ErrorCode::ERROR_ABNORMAL:
110 code = DpsError::DPS_ERROR_IMAGE_PROC_ABNORMAL;
111 break;
112 case OHOS::HDI::Camera::V1_2::ErrorCode::ERROR_ABORT:
113 code = DpsError::DPS_ERROR_IMAGE_PROC_INTERRUPTED;
114 break;
115 default:
116 DP_ERR_LOG("unexpected error code: %{public}d.", errorCode);
117 break;
118 }
119 return code;
120 }
121
MapHdiStatus(OHOS::HDI::Camera::V1_2::SessionStatus statusCode)122 HdiStatus MapHdiStatus(OHOS::HDI::Camera::V1_2::SessionStatus statusCode)
123 {
124 HdiStatus code = HdiStatus::HDI_DISCONNECTED;
125 switch (statusCode) {
126 case OHOS::HDI::Camera::V1_2::SessionStatus::SESSION_STATUS_READY:
127 code = HdiStatus::HDI_READY;
128 break;
129 case OHOS::HDI::Camera::V1_2::SessionStatus::SESSION_STATUS_READY_SPACE_LIMIT_REACHED:
130 code = HdiStatus::HDI_READY_SPACE_LIMIT_REACHED;
131 break;
132 case OHOS::HDI::Camera::V1_2::SessionStatus::SESSSON_STATUS_NOT_READY_TEMPORARILY:
133 code = HdiStatus::HDI_NOT_READY_TEMPORARILY;
134 break;
135 case OHOS::HDI::Camera::V1_2::SessionStatus::SESSION_STATUS_NOT_READY_OVERHEAT:
136 code = HdiStatus::HDI_NOT_READY_OVERHEAT;
137 break;
138 case OHOS::HDI::Camera::V1_2::SessionStatus::SESSION_STATUS_NOT_READY_PREEMPTED:
139 code = HdiStatus::HDI_NOT_READY_PREEMPTED;
140 break;
141 default:
142 DP_ERR_LOG("unexpected error code: %{public}d.", statusCode);
143 break;
144 }
145 return code;
146 }
147
MapToHdiExecutionMode(ExecutionMode executionMode)148 OHOS::HDI::Camera::V1_2::ExecutionMode MapToHdiExecutionMode(ExecutionMode executionMode)
149 {
150 auto mode = OHOS::HDI::Camera::V1_2::ExecutionMode::LOW_POWER;
151 switch (executionMode) {
152 case ExecutionMode::HIGH_PERFORMANCE:
153 mode = OHOS::HDI::Camera::V1_2::ExecutionMode::HIGH_PREFORMANCE;
154 break;
155 case ExecutionMode::LOAD_BALANCE:
156 mode = OHOS::HDI::Camera::V1_2::ExecutionMode::BALANCED;
157 break;
158 case ExecutionMode::LOW_POWER:
159 mode = OHOS::HDI::Camera::V1_2::ExecutionMode::LOW_POWER;
160 break;
161 default:
162 DP_ERR_LOG("unexpected error code: %{public}d.", executionMode);
163 break;
164 }
165 return mode;
166 }
167
ConvertPhotoThermalLevel(int32_t level)168 SystemPressureLevel ConvertPhotoThermalLevel(int32_t level)
169 {
170 if (level < LEVEL_0 || level > LEVEL_5) {
171 return SystemPressureLevel::SEVERE;
172 }
173 SystemPressureLevel eventLevel = SystemPressureLevel::SEVERE;
174 switch (level) {
175 case LEVEL_0:
176 case LEVEL_1:
177 eventLevel = SystemPressureLevel::NOMINAL;
178 break;
179 case LEVEL_2:
180 case LEVEL_3:
181 case LEVEL_4:
182 eventLevel = SystemPressureLevel::FAIR;
183 break;
184 default:
185 eventLevel = SystemPressureLevel::SEVERE;
186 break;
187 }
188 return eventLevel;
189 }
190
ConvertVideoThermalLevel(int32_t level)191 VideoThermalLevel ConvertVideoThermalLevel(int32_t level)
192 {
193 DP_CHECK_RETURN_RET(level == ThermalLevel::LEVEL_0, VideoThermalLevel::COOL);
194 return VideoThermalLevel::HOT;
195 }
196 } // namespace DeferredProcessing
197 } // namespace CameraStandard
198 } // namespace OHOS