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