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 #ifndef OHOS_CAMERA_UTIL_H
17 #define OHOS_CAMERA_UTIL_H
18
19 #include <limits.h>
20 #include "display_type.h"
21 #include "v1_0/types.h"
22 #include "camera_metadata_info.h"
23 #include <malloc.h>
24 #include "safe_map.h"
25
26 namespace OHOS {
27 namespace CameraStandard {
28 using namespace OHOS::HDI::Camera::V1_0;
29 static constexpr int32_t CAMERA_COLOR_SPACE = 8;
30 static const std::string OHOS_PERMISSION_CAMERA = "ohos.permission.CAMERA";
31 static const std::string OHOS_PERMISSION_MANAGE_CAMERA_CONFIG = "ohos.permission.MANAGE_CAMERA_CONFIG";
32 enum CamServiceError {
33 CAMERA_OK = 0,
34 CAMERA_ALLOC_ERROR,
35 CAMERA_INVALID_ARG,
36 CAMERA_UNSUPPORTED,
37 CAMERA_DEVICE_BUSY,
38 CAMERA_DEVICE_CLOSED,
39 CAMERA_DEVICE_REQUEST_TIMEOUT,
40 CAMERA_STREAM_BUFFER_LOST,
41 CAMERA_INVALID_SESSION_CFG,
42 CAMERA_CAPTURE_LIMIT_EXCEED,
43 CAMERA_INVALID_STATE,
44 CAMERA_UNKNOWN_ERROR,
45 CAMERA_DEVICE_PREEMPTED,
46 CAMERA_OPERATION_NOT_ALLOWED
47 };
48
49 enum ClientPriorityLevels {
50 PRIORITY_LEVEL_SAME = 0,
51 PRIORITY_LEVEL_LOWER,
52 PRIORITY_LEVEL_HIGHER
53 };
54
55
56 extern std::unordered_map<int32_t, int32_t> g_cameraToPixelFormat;
57 extern std::map<int, std::string> g_cameraPos;
58 extern std::map<int, std::string> g_cameraType;
59 extern std::map<int, std::string> g_cameraConType;
60 extern std::map<int, std::string> g_cameraFormat;
61 extern std::map<int, std::string> g_cameraFocusMode;
62 extern std::map<int, std::string> g_cameraExposureMode;
63 extern std::map<int, std::string> g_cameraFlashMode;
64 extern std::map<int, std::string> g_cameraVideoStabilizationMode;
65 extern std::map<int, std::string> g_cameraPrelaunchAvailable;
66 extern std::map<int, std::string> g_cameraQuickThumbnailAvailable;
67
DisableJeMalloc()68 inline void DisableJeMalloc()
69 {
70 #ifdef CONFIG_USE_JEMALLOC_DFX_INTF
71 mallopt(M_SET_THREAD_CACHE, M_THREAD_CACHE_DISABLE);
72 mallopt(M_DELAYED_FREE, M_DELAYED_FREE_DISABLE);
73 mallopt(M_FLUSH_THREAD_CACHE, 0);
74 #endif
75 }
76
77 int32_t HdiToServiceError(CamRetCode ret);
78
79 std::string CreateMsg(const char* format, ...);
80
81 int32_t AllocateCaptureId(int32_t &captureId);
82
83 void ReleaseCaptureId(int32_t captureId);
84
85 bool IsValidTokenId(uint32_t tokenId);
86
87 int32_t GetVersionId(uint32_t major, uint32_t minor);
88
89 bool IsValidSize(
90 std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility, int32_t format, int32_t width, int32_t height);
91
92 int32_t JudgmentPriority(const pid_t& pid, const pid_t& pidCompared);
93
94 bool IsSameClient(const pid_t& pid, const pid_t& pidCompared);
95
96 bool IsInForeGround(const uint32_t callerToken);
97
98 bool IsCameraNeedClose(const uint32_t callerToken, const pid_t& pid, const pid_t& pidCompared);
99
100 int32_t CheckPermission(std::string permissionName, uint32_t callerToken);
101 } // namespace CameraStandard
102 } // namespace OHOS
103 #endif // OHOS_CAMERA_UTIL_H
104