• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef HARDWARE_GOOGLE_CAMERA_HAL_UTILS_UTILS_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_UTILS_UTILS_H_
19 
20 #include <log/log.h>
21 
22 #include <set>
23 #include <utility>
24 
25 #include "hal_types.h"
26 
27 namespace android {
28 namespace google_camera_hal {
29 namespace utils {
30 
31 bool IsPreviewStream(const Stream& stream);
32 bool IsJPEGSnapshotStream(const Stream& stream);
33 bool IsVideoStream(const Stream& stream);
34 bool IsRawStream(const Stream& stream);
35 bool IsInputRawStream(const Stream& stream);
36 bool IsArbitraryDataSpaceRawStream(const Stream& stream);
37 bool IsYUVSnapshotStream(const Stream& stream);
38 bool IsDepthStream(const Stream& stream);
39 bool IsOutputZslStream(const Stream& stream);
40 bool IsSoftwareDenoiseEligibleSnapshotStream(const Stream& stream);
41 bool IsSecuredStream(const Stream& stream);
42 bool IsStreamUseCasesVideoCall(const Stream& stream);
43 bool IsHdrStream(const Stream& stream);
44 
45 bool HasCapability(const HalCameraMetadata* metadata, uint8_t capability);
46 
47 status_t GetSensorPhysicalSize(const HalCameraMetadata* characteristics,
48                                float* width, float* height);
49 
50 status_t GetSensorActiveArraySize(const HalCameraMetadata* characteristics,
51                                   Rect* active_array,
52                                   bool maximum_resolution = false);
53 
54 status_t GetSensorPixelArraySize(const HalCameraMetadata* characteristics,
55                                  Dimension* pixel_array);
56 
57 status_t GetFocalLength(const HalCameraMetadata* characteristics,
58                         float* focal_length);
59 
60 status_t GetZoomRatioRange(const HalCameraMetadata* characteristics,
61                            ZoomRatioRange* zoom_ratio_range);
62 
63 // Return if LiveSnapshot is configured
64 bool IsLiveSnapshotConfigured(const StreamConfiguration& stream_config);
65 
66 // Return true if max fps is the same at high speed mode
67 bool IsHighSpeedModeFpsCompatible(StreamConfigurationMode mode,
68                                   const HalCameraMetadata* old_session,
69                                   const HalCameraMetadata* new_session);
70 
71 // This method is for IsReconfigurationRequired purpose
72 // Return true if meet any condition below
73 // 1. Any session entry count is zero
74 // 2. All metadata are the same between old and new session.
75 //    For ANDROID_CONTROL_AE_TARGET_FPS_RANGE, only compare max fps.
76 bool IsSessionParameterCompatible(const HalCameraMetadata* old_session,
77                                   const HalCameraMetadata* new_session);
78 
79 bool SupportRealtimeThread();
80 status_t SetRealtimeThread(pthread_t thread);
81 status_t UpdateThreadSched(pthread_t thread, int32_t policy,
82                            struct sched_param* param);
83 
84 status_t GetStreamUseCases(const HalCameraMetadata* static_metadata,
85                            std::set<int64_t>* stream_use_cases);
86 
87 bool IsStreamUseCaseSupported(const StreamConfiguration& stream_config,
88                               const std::set<int64_t>& stream_use_cases,
89                               bool log_if_not_supported = true);
90 
91 // Map the rectangle to the coordination of HAL.
92 void ConvertZoomRatio(float zoom_ratio, const Dimension& active_array_dimension,
93                       int32_t* left, int32_t* top, int32_t* width,
94                       int32_t* height);
95 
96 // Clamp the coordinate boundary within dimension.
97 template <typename T>
98 void ClampBoundary(const Dimension& active_array_dimension, T* x, T* y,
99                    T* width = nullptr, T* height = nullptr) {
100   if (x == nullptr || y == nullptr) {
101     ALOGE("%s, invalid params", __FUNCTION__);
102     return;
103   }
104   *x = std::clamp(*x, static_cast<T>(0),
105                   static_cast<T>(active_array_dimension.width - 1));
106   *y = std::clamp(*y, static_cast<T>(0),
107                   static_cast<T>(active_array_dimension.height - 1));
108 
109   if (width) {
110     *width = std::clamp(*width, static_cast<T>(1),
111                         static_cast<T>(active_array_dimension.width - *x));
112   }
113   if (height) {
114     *height = std::clamp(*height, static_cast<T>(1),
115                          static_cast<T>(active_array_dimension.height - *y));
116   }
117 }
118 
119 // Map the position to the coordinate of framework.
120 template <typename T>
121 void RevertZoomRatio(const float zoom_ratio,
122                      const Dimension& active_array_dimension,
123                      const bool round_to_int, T* x, T* y, T* width = nullptr,
124                      T* height = nullptr) {
125   if (x == nullptr || y == nullptr) {
126     ALOGE("%s, invalid params", __FUNCTION__);
127     return;
128   }
129   float tmp_x = *x * zoom_ratio -
130                 0.5f * active_array_dimension.width * (zoom_ratio - 1.0f);
131   float tmp_y = *y * zoom_ratio -
132                 0.5f * active_array_dimension.height * (zoom_ratio - 1.0f);
133 
134   if (round_to_int) {
135     *x = std::round(tmp_x);
136     *y = std::round(tmp_y);
137   } else {
138     *x = tmp_x;
139     *y = tmp_y;
140   }
141 
142   if (width) {
143     *width = std::round(*width * zoom_ratio);
144   }
145   if (height) {
146     *height = std::round(*height * zoom_ratio);
147   }
148   ClampBoundary(active_array_dimension, x, y, width, height);
149 }
150 
151 std::vector<std::string> FindLibraryPaths(const char* dir_path);
152 
153 }  // namespace utils
154 }  // namespace google_camera_hal
155 }  // namespace android
156 
157 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_UTILS_UTILS_H_
158