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_GOOGLE_CAMERA_HAL_HAL_UTILS_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_HAL_UTILS_H_
19 
20 #include "hal_types.h"
21 #include "hwl_types.h"
22 #include "process_block.h"
23 #include "utils.h"
24 
25 namespace android {
26 namespace google_camera_hal {
27 namespace hal_utils {
28 
29 // Create a HWL pipeline request for a pipeline based on a capture request.
30 status_t CreateHwlPipelineRequest(HwlPipelineRequest* hwl_request,
31                                   uint32_t pipeline_id,
32                                   const CaptureRequest& request);
33 
34 // Create a vector of sychrounous HWL pipeline requests for pipelines
35 // based on capture requests.
36 // pipeline_ids and requests must have the same size.
37 // One HWL request will be created for each pair of a pipeline ID and a request.
38 status_t CreateHwlPipelineRequests(
39     std::vector<HwlPipelineRequest>* hwl_requests,
40     const std::vector<uint32_t>& pipeline_ids,
41     const std::vector<ProcessBlockRequest>& requests);
42 
43 // Convert a HWL result to a capture result.
44 std::unique_ptr<CaptureResult> ConvertToCaptureResult(
45     std::unique_ptr<HwlPipelineResult> hwl_result);
46 
47 // Return if the request contains an output buffer.
48 bool ContainsOutputBuffer(const CaptureRequest& request,
49                           const buffer_handle_t& buffer);
50 
51 // Return if all output buffers in remaining_session_request are included in
52 // process_block_requests.
53 bool AreAllRemainingBuffersRequested(
54     const std::vector<ProcessBlockRequest>& process_block_requests,
55     const CaptureRequest& remaining_session_request);
56 
57 // Return if this is an IR camera.
58 bool IsIrCamera(const HalCameraMetadata* characteristics);
59 
60 // Return if this is an MONO camera.
61 bool IsMonoCamera(const HalCameraMetadata* characteristics);
62 
63 // Return if this is a bayer camera.
64 bool IsBayerCamera(const HalCameraMetadata* characteristics);
65 
66 // Return if this is a HDR+ request
67 bool IsRequestHdrplusCompatible(const CaptureRequest& request,
68                                 int32_t preview_stream_id);
69 
70 // Return true if this is a fixed-focus camera.
71 bool IsFixedFocusCamera(const HalCameraMetadata* characteristics);
72 
73 // Return if HDR+ stream is supported
74 bool IsStreamHdrplusCompatible(const StreamConfiguration& stream_config,
75                                const HalCameraMetadata* characteristics);
76 
77 // Set ANDROID_CONTROL_ENABLE_ZSL metadata
78 status_t SetEnableZslMetadata(HalCameraMetadata* metadata, bool enable);
79 
80 // Set hybrid AE vendor tag
81 status_t SetHybridAeMetadata(HalCameraMetadata* metadata, bool enable);
82 
83 // Modify the request of realtime pipeline for HDR+
84 status_t ModifyRealtimeRequestForHdrplus(HalCameraMetadata* metadata,
85                                          const bool hybrid_ae_enable = true);
86 
87 // Get ANDROID_STATISTICS_FACE_DETECT_MODE
88 status_t GetFdMode(const CaptureRequest& request, uint8_t* face_detect_mode);
89 
90 // Remove face detect information
91 status_t RemoveFdInfoFromResult(HalCameraMetadata* metadata);
92 
93 // Force lens shading map mode on
94 status_t ForceLensShadingMapModeOn(HalCameraMetadata* metadata);
95 
96 // Get lens shading map mode
97 status_t GetLensShadingMapMode(const CaptureRequest& request,
98                                uint8_t* lens_shading_mode);
99 
100 // Remove lens shading information
101 status_t RemoveLsInfoFromResult(HalCameraMetadata* metadata);
102 
103 // Dump the information in the stream configuration
104 void DumpStreamConfiguration(const StreamConfiguration& stream_configuration,
105                              const std::string& title);
106 
107 // Dump the information in the HAL configured streams
108 void DumpHalConfiguredStreams(
109     const std::vector<HalStream>& hal_configured_streams,
110     const std::string& title);
111 
112 // Dump the information in a capture request
113 void DumpCaptureRequest(const CaptureRequest& request, const std::string& title);
114 
115 // Dump the information in a capture result
116 void DumpCaptureResult(const ProcessBlockResult& result,
117                        const std::string& title);
118 
119 // Dump the information in a capture result
120 void DumpCaptureResult(const CaptureResult& result, const std::string& title);
121 
122 // Dump the information in a notification
123 void DumpNotify(const NotifyMessage& message, const std::string& title);
124 
125 // Dump Stream
126 void DumpStream(const Stream& stream, const std::string& title);
127 
128 // Dump HalStream
129 void DumpHalStream(const HalStream& hal_stream, const std::string& title);
130 
131 // Dump the information in a buffer return
132 void DumpBufferReturn(const std::vector<StreamBuffer>& stream_buffers,
133                       const std::string& title);
134 
135 // Dump the information in a buffer request
136 void DumpBufferRequest(const std::vector<BufferRequest>& hal_buffer_requests,
137                        const std::vector<BufferReturn>* hal_buffer_returns,
138                        const std::string& title);
139 
140 }  // namespace hal_utils
141 }  // namespace google_camera_hal
142 }  // namespace android
143 
144 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_HAL_UTILS_H_