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_HWL_INTERFACE_HWL_TYPES_H_ 18 #define HARDWARE_GOOGLE_CAMERA_HAL_HWL_INTERFACE_HWL_TYPES_H_ 19 20 #include <cstdint> 21 #include <functional> 22 #include <limits> 23 #include <string> 24 #include <unordered_set> 25 #include <vector> 26 27 #include "hal_types.h" 28 29 namespace android { 30 namespace google_camera_hal { 31 32 // Controls what memory is pinned and madvised 33 struct HwlMemoryConfig { 34 // Defines which libraries to pin in memory. 35 std::unordered_set<std::string> pinned_libraries; 36 37 // Sets the maximum size of a map to be madvised. 38 size_t madvise_map_size_limit_bytes = std::numeric_limits<size_t>::max(); 39 }; 40 41 // Enumerates pipeline roles that are used to communicate with HWL. 42 enum class HwlOfflinePipelineRole { 43 kOfflineInvalidRole = 0, 44 kOfflineSmoothTransitionRole, 45 kOfflineHdrplusRole, 46 }; 47 48 // Define a HWL pipeline request. 49 struct HwlPipelineRequest { 50 // ID of the pipeline that this request should be submitted to. 51 uint32_t pipeline_id = 0; 52 53 std::unique_ptr<HalCameraMetadata> settings; 54 55 // If empty, the output buffers are captured from the camera sensors. If 56 // not empty, the output buffers are captured from the input buffers. 57 std::vector<StreamBuffer> input_buffers; 58 59 // The metadata of the input_buffers. This is used for multi-frame merging 60 // like HDR+. 61 std::vector<std::unique_ptr<HalCameraMetadata>> input_buffer_metadata; 62 63 std::vector<StreamBuffer> output_buffers; 64 65 // Maps from physical camera ID to physical camera settings. 66 std::unordered_map<uint32_t, std::unique_ptr<HalCameraMetadata>> 67 physical_camera_settings; 68 69 int32_t input_width; 70 int32_t input_height; 71 }; 72 73 // Define a HWL pipeline result. 74 struct HwlPipelineResult { 75 // camera_id, pipeline_id, frame_number should match those in the original 76 // request. 77 uint32_t camera_id = 0; 78 uint32_t pipeline_id = 0; 79 uint32_t frame_number = 0; 80 81 // result_metadata, input_buffers, and output_buffers can be returned 82 // separately. 83 std::unique_ptr<HalCameraMetadata> result_metadata; 84 std::vector<StreamBuffer> input_buffers; 85 std::vector<StreamBuffer> output_buffers; 86 87 // Maps from physical camera ID to physical camera results. 88 // Only to be used for logical cameras that receive requests 89 // with output buffers belonging to streams tied to physical devices. 90 std::unordered_map<uint32_t, std::unique_ptr<HalCameraMetadata>> 91 physical_camera_results; 92 93 uint32_t partial_result = 0; 94 }; 95 96 // Callback to invoke to send a result from HWL. 97 using HwlProcessPipelineResultFunc = 98 std::function<void(std::unique_ptr<HwlPipelineResult> /*result*/)>; 99 100 // Callback to invoke to send a batched result from HWL. 101 using HwlProcessPipelineBatchResultFunc = std::function<void( 102 std::vector<std::unique_ptr<HwlPipelineResult>> /*results*/)>; 103 104 // Callback to invoke to notify a message from HWL. 105 using NotifyHwlPipelineMessageFunc = std::function<void( 106 uint32_t /*pipeline_id*/, const NotifyMessage& /*message*/)>; 107 108 // Callback to notify a batched message from HWL. 109 using NotifyHwlPipelineBatchMessageFunc = 110 std::function<void(const std::vector<NotifyMessage>& /*messages*/)>; 111 112 // Defines callbacks to notify from a HWL pipeline. 113 struct HwlPipelineCallback { 114 // Callback to notify when a HWL pipeline produces a capture result. 115 HwlProcessPipelineResultFunc process_pipeline_result; 116 117 // Callback to notify when a HWL pipeline produces a batched capture result. 118 HwlProcessPipelineBatchResultFunc process_pipeline_batch_result; 119 120 // Callback to notify shutters or errors. 121 NotifyHwlPipelineMessageFunc notify; 122 123 // Callback to notify batched shutters or errors. 124 NotifyHwlPipelineBatchMessageFunc notify_batch; 125 }; 126 127 // Callback to invoke to request buffers from HAL. Only in case of HFR, there 128 // is a chance for the client to ask for more than one buffer each time 129 // (in batch). 130 // TODO(b/134959043): a more decoupled implementation of HAL Buffer Management 131 // allowos us to remove the frame_number from the arg list. 132 using HwlRequestBuffersFunc = std::function<status_t( 133 uint32_t /*stream_id*/, uint32_t /*num_buffers*/, 134 std::vector<StreamBuffer>* /*buffers*/, uint32_t /*frame_number*/)>; 135 136 // Callback to invoke to return buffers, acquired by HwlRequestBuffersFunc, 137 // to HAL. 138 using HwlReturnBuffersFunc = 139 std::function<void(const std::vector<StreamBuffer>& /*buffers*/)>; 140 141 // Defines callbacks to invoke from a HWL session. 142 struct HwlSessionCallback { 143 // Callback to request stream buffers. 144 HwlRequestBuffersFunc request_stream_buffers; 145 146 // Callback to return stream buffers. 147 HwlReturnBuffersFunc return_stream_buffers; 148 }; 149 150 // Callback defined from framework to indicate the state of camera device 151 // has changed. 152 using HwlCameraDeviceStatusChangeFunc = 153 std::function<void(uint32_t /*camera_id*/, CameraDeviceStatus /*new_status*/)>; 154 155 // Callback defined from framework to indicate the state of physical camera 156 // device has changed. 157 using HwlPhysicalCameraDeviceStatusChangeFunc = 158 std::function<void(uint32_t /*camera_id*/, uint32_t /*physical_camera_id*/, 159 CameraDeviceStatus /*new_status*/)>; 160 161 // Callback defined from framework to indicate the state of the torch mode 162 // has changed. 163 using HwlTorchModeStatusChangeFunc = 164 std::function<void(uint32_t /*camera_id*/, TorchModeStatus /*new_status*/)>; 165 166 // Defines callbacks to notify when a status changed. 167 struct HwlCameraProviderCallback { 168 // Callback to notify when a camera device's status changed. 169 HwlCameraDeviceStatusChangeFunc camera_device_status_change; 170 171 // Callback to notify when a physical camera device's status changed. 172 HwlPhysicalCameraDeviceStatusChangeFunc physical_camera_device_status_change; 173 174 // Callback to notify when a torch mode status changed. 175 HwlTorchModeStatusChangeFunc torch_mode_status_change; 176 }; 177 178 } // namespace google_camera_hal 179 } // namespace android 180 181 #endif // HARDWARE_GOOGLE_CAMERA_HAL_HWL_INTERFACE_HWL_TYPES_H_ 182