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
25 namespace OHOS {
26 namespace CameraStandard {
27 using namespace OHOS::HDI::Camera::V1_0;
28 static constexpr int32_t CAMERA_COLOR_SPACE = 8;
29
30 enum CamServiceError {
31 CAMERA_OK = 0,
32 CAMERA_ALLOC_ERROR,
33 CAMERA_INVALID_ARG,
34 CAMERA_UNSUPPORTED,
35 CAMERA_DEVICE_BUSY,
36 CAMERA_DEVICE_CLOSED,
37 CAMERA_DEVICE_REQUEST_TIMEOUT,
38 CAMERA_STREAM_BUFFER_LOST,
39 CAMERA_INVALID_SESSION_CFG,
40 CAMERA_CAPTURE_LIMIT_EXCEED,
41 CAMERA_INVALID_STATE,
42 CAMERA_UNKNOWN_ERROR,
43 CAMERA_DEVICE_PREEMPTED,
44 CAMERA_OPERATION_NOT_ALLOWED
45 };
46
47 extern std::unordered_map<int32_t, int32_t> g_cameraToPixelFormat;
48 extern std::map<int, std::string> g_cameraPos;
49 extern std::map<int, std::string> g_cameraType;
50 extern std::map<int, std::string> g_cameraConType;
51 extern std::map<int, std::string> g_cameraFormat;
52 extern std::map<int, std::string> g_cameraFocusMode;
53 extern std::map<int, std::string> g_cameraExposureMode;
54 extern std::map<int, std::string> g_cameraFlashMode;
55 extern std::map<int, std::string> g_cameraVideoStabilizationMode;
56
DisableJeMalloc()57 inline void DisableJeMalloc()
58 {
59 #ifdef CONFIG_USE_JEMALLOC_DFX_INTF
60 mallopt(M_SET_THREAD_CACHE, M_THREAD_CACHE_DISABLE);
61 mallopt(M_DELAYED_FREE, M_DELAYED_FREE_DISABLE);
62 mallopt(M_FLUSH_THREAD_CACHE, 0);
63 #endif
64 }
65
66 int32_t HdiToServiceError(CamRetCode ret);
67
68 std::string CreateMsg(const char* format, ...);
69
70 int32_t AllocateCaptureId(int32_t &captureId);
71
72 void ReleaseCaptureId(int32_t captureId);
73
74 bool IsValidTokenId(uint32_t tokenId);
75
76 bool IsValidSize(
77 std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility, int32_t format, int32_t width, int32_t height);
78 } // namespace CameraStandard
79 } // namespace OHOS
80 #endif // OHOS_CAMERA_UTIL_H
81