• 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 <utility>
23 
24 #include "hal_types.h"
25 
26 namespace android {
27 namespace google_camera_hal {
28 namespace utils {
29 
30 bool IsPreviewStream(const Stream& stream);
31 bool IsJPEGSnapshotStream(const Stream& stream);
32 bool IsVideoStream(const Stream& stream);
33 bool IsRawStream(const Stream& stream);
34 bool IsInputRawStream(const Stream& stream);
35 bool IsArbitraryDataSpaceRawStream(const Stream& stream);
36 bool IsYUVSnapshotStream(const Stream& stream);
37 bool IsDepthStream(const Stream& stream);
38 bool IsOutputZslStream(const Stream& stream);
39 
40 bool HasCapability(const HalCameraMetadata* metadata, uint8_t capability);
41 
42 status_t GetSensorPhysicalSize(const HalCameraMetadata* characteristics,
43                                float* width, float* height);
44 
45 status_t GetSensorActiveArraySize(const HalCameraMetadata* characteristics,
46                                   Rect* active_array,
47                                   bool maximum_resolution = false);
48 
49 status_t GetSensorPixelArraySize(const HalCameraMetadata* characteristics,
50                                  Dimension* pixel_array);
51 
52 status_t GetFocalLength(const HalCameraMetadata* characteristics,
53                         float* focal_length);
54 
55 status_t GetZoomRatioRange(const HalCameraMetadata* characteristics,
56                            ZoomRatioRange* zoom_ratio_range);
57 
58 // Return if LiveSnapshot is configured
59 bool IsLiveSnapshotConfigured(const StreamConfiguration& stream_config);
60 
61 // Return true if max fps is the same at high speed mode
62 bool IsHighSpeedModeFpsCompatible(StreamConfigurationMode mode,
63                                   const HalCameraMetadata* old_session,
64                                   const HalCameraMetadata* new_session);
65 
66 // This method is for IsReconfigurationRequired purpose
67 // Return true if meet any condition below
68 // 1. Any session entry count is zero
69 // 2. All metadata are the same between old and new session.
70 //    For ANDROID_CONTROL_AE_TARGET_FPS_RANGE, only compare max fps.
71 bool IsSessionParameterCompatible(const HalCameraMetadata* old_session,
72                                   const HalCameraMetadata* new_session);
73 
74 bool SupportRealtimeThread();
75 status_t SetRealtimeThread(pthread_t thread);
76 status_t UpdateThreadSched(pthread_t thread, int32_t policy,
77                            struct sched_param* param);
78 
79 // Map the rectangle to the coordination of HAL.
80 void ConvertZoomRatio(float zoom_ratio, const Dimension& active_array_dimension,
81                       int32_t* left, int32_t* top, int32_t* width,
82                       int32_t* height);
83 
84 // Clamp the coordinate boundary within dimension.
85 template <typename T>
86 void ClampBoundary(const Dimension& active_array_dimension, T* x, T* y,
87                    T* width = nullptr, T* height = nullptr) {
88   if (x == nullptr || y == nullptr) {
89     ALOGE("%s, invalid params", __FUNCTION__);
90     return;
91   }
92   *x = std::clamp(*x, static_cast<T>(0),
93                   static_cast<T>(active_array_dimension.width - 1));
94   *y = std::clamp(*y, static_cast<T>(0),
95                   static_cast<T>(active_array_dimension.height - 1));
96 
97   if (width) {
98     *width = std::clamp(*width, static_cast<T>(1),
99                         static_cast<T>(active_array_dimension.width - *x));
100   }
101   if (height) {
102     *height = std::clamp(*height, static_cast<T>(1),
103                          static_cast<T>(active_array_dimension.height - *y));
104   }
105 }
106 
107 // Map the position to the coordinate of framework.
108 template <typename T>
109 void RevertZoomRatio(const float zoom_ratio,
110                      const Dimension& active_array_dimension,
111                      const bool round_to_int, T* x, T* y, T* width = nullptr,
112                      T* height = nullptr) {
113   if (x == nullptr || y == nullptr) {
114     ALOGE("%s, invalid params", __FUNCTION__);
115     return;
116   }
117   float tmp_x = *x * zoom_ratio -
118                 0.5f * active_array_dimension.width * (zoom_ratio - 1.0f);
119   float tmp_y = *y * zoom_ratio -
120                 0.5f * active_array_dimension.height * (zoom_ratio - 1.0f);
121 
122   if (round_to_int) {
123     *x = std::round(tmp_x);
124     *y = std::round(tmp_y);
125   } else {
126     *x = tmp_x;
127     *y = tmp_y;
128   }
129 
130   if (width) {
131     *width = std::round(*width * zoom_ratio);
132   }
133   if (height) {
134     *height = std::round(*height * zoom_ratio);
135   }
136   ClampBoundary(active_array_dimension, x, y, width, height);
137 }
138 
139 std::vector<std::string> FindLibraryPaths(const char* dir_path);
140 
141 }  // namespace utils
142 }  // namespace google_camera_hal
143 }  // namespace android
144 
145 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_UTILS_UTILS_H_
146