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