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