• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_CAMERA_UTIL_H
17 #define OHOS_CAMERA_UTIL_H
18 
19 #include "display_type.h"
20 #include <limits.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 
33 enum CamServiceError {
34     CAMERA_OK = 0,
35     CAMERA_ALLOC_ERROR,
36     CAMERA_INVALID_ARG,
37     CAMERA_UNSUPPORTED,
38     CAMERA_DEVICE_BUSY,
39     CAMERA_DEVICE_CLOSED,
40     CAMERA_DEVICE_REQUEST_TIMEOUT,
41     CAMERA_STREAM_BUFFER_LOST,
42     CAMERA_INVALID_SESSION_CFG,
43     CAMERA_CAPTURE_LIMIT_EXCEED,
44     CAMERA_INVALID_STATE,
45     CAMERA_UNKNOWN_ERROR,
46     CAMERA_DEVICE_PREEMPTED,
47     CAMERA_OPERATION_NOT_ALLOWED
48 };
49 
50 extern std::unordered_map<int32_t, int32_t> g_cameraToPixelFormat;
51 extern std::map<int, std::string> g_cameraPos;
52 extern std::map<int, std::string> g_cameraType;
53 extern std::map<int, std::string> g_cameraConType;
54 extern std::map<int, std::string> g_cameraFormat;
55 extern std::map<int, std::string> g_cameraFocusMode;
56 extern std::map<int, std::string> g_cameraExposureMode;
57 extern std::map<int, std::string> g_cameraFlashMode;
58 extern std::map<int, std::string> g_cameraVideoStabilizationMode;
59 
DisableJeMalloc()60 inline void DisableJeMalloc()
61 {
62 #ifdef CONFIG_USE_JEMALLOC_DFX_INTF
63     mallopt(M_SET_THREAD_CACHE, M_THREAD_CACHE_DISABLE);
64     mallopt(M_DELAYED_FREE, M_DELAYED_FREE_DISABLE);
65     mallopt(M_FLUSH_THREAD_CACHE, 0);
66 #endif
67 }
68 
69 int32_t HdiToServiceError(CamRetCode ret);
70 
71 std::string CreateMsg(const char* format, ...);
72 
73 int32_t AllocateCaptureId(int32_t &captureId);
74 
75 void ReleaseCaptureId(int32_t captureId);
76 
77 bool IsValidTokenId(uint32_t tokenId);
78 
79 bool IsValidSize(
80     std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility, int32_t format, int32_t width, int32_t height);
81 
82 int32_t CheckPermission(std::string permissionName, uint32_t callerToken);
83 } // namespace CameraStandard
84 } // namespace OHOS
85 #endif // OHOS_CAMERA_UTIL_H
86