• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_HIDL_SERVICE_HIDL_UTILS_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_UTILS_H_
19 
20 #include <android/hardware/camera/common/1.0/types.h>
21 #include <android/hardware/camera/device/3.7/ICameraDeviceSession.h>
22 #include <fmq/MessageQueue.h>
23 #include <hal_types.h>
24 #include <hidl/HidlSupport.h>
25 #include <memory>
26 
27 namespace android {
28 namespace hardware {
29 namespace camera {
30 namespace implementation {
31 namespace hidl_utils {
32 
33 using ::android::hardware::hidl_vec;
34 using ::android::hardware::camera::common::V1_0::CameraDeviceStatus;
35 using ::android::hardware::camera::common::V1_0::CameraMetadataType;
36 using ::android::hardware::camera::common::V1_0::CameraResourceCost;
37 using ::android::hardware::camera::common::V1_0::Status;
38 using ::android::hardware::camera::common::V1_0::TorchMode;
39 using ::android::hardware::camera::common::V1_0::TorchModeStatus;
40 using ::android::hardware::camera::common::V1_0::VendorTagSection;
41 using ::android::hardware::camera::device::V3_2::BufferCache;
42 using ::android::hardware::camera::device::V3_2::BufferStatus;
43 using ::android::hardware::camera::device::V3_2::CameraMetadata;
44 using ::android::hardware::camera::device::V3_2::NotifyMsg;
45 using ::android::hardware::camera::device::V3_2::RequestTemplate;
46 using ::android::hardware::camera::device::V3_2::StreamBuffer;
47 using ::android::hardware::camera::device::V3_2::StreamConfigurationMode;
48 using ::android::hardware::camera::device::V3_2::StreamRotation;
49 using ::android::hardware::camera::device::V3_2::StreamType;
50 using ::android::hardware::camera::device::V3_4::CaptureResult;
51 using ::android::hardware::camera::device::V3_4::Stream;
52 using ::android::hardware::camera::device::V3_5::BufferRequest;
53 using ::android::hardware::camera::device::V3_5::BufferRequestStatus;
54 using ::android::hardware::camera::device::V3_5::StreamBufferRequestError;
55 using ::android::hardware::camera::device::V3_5::StreamBufferRet;
56 using ::android::hardware::camera::device::V3_5::StreamBuffersVal;
57 using ::android::hardware::camera::device::V3_6::HalStreamConfiguration;
58 using ::android::hardware::camera::device::V3_7::CaptureRequest;
59 using ::android::hardware::camera::device::V3_7::StreamConfiguration;
60 
61 // Util functions to convert the types between HIDL and Google Camera HAL.
62 
63 // Conversions from HAL to HIDL
64 status_t ConvertToHidlVendorTagSections(
65     const std::vector<google_camera_hal::VendorTagSection>& hal_sections,
66     hidl_vec<VendorTagSection>* hidl_sections);
67 
68 status_t ConvertToHidlVendorTagType(
69     google_camera_hal::CameraMetadataType hal_type,
70     CameraMetadataType* hidl_type);
71 
72 status_t ConvertToHidlResourceCost(
73     const google_camera_hal::CameraResourceCost& hal_cost,
74     CameraResourceCost* hidl_cost);
75 
76 status_t ConvertToHidlHalStreamConfig(
77     const std::vector<google_camera_hal::HalStream>& hal_configured_streams,
78     HalStreamConfiguration* hidl_hal_stream_config);
79 
80 // Convert a HAL result to a HIDL result. It will try to write the result
81 // metadata to result_metadata_queue. If it fails, it will write the result
82 // metadata in hidl_result.
83 status_t ConvertToHidlCaptureResult(
84     MessageQueue<uint8_t, kSynchronizedReadWrite>* result_metadata_queue,
85     std::unique_ptr<google_camera_hal::CaptureResult> hal_result,
86     CaptureResult* hidl_result);
87 
88 status_t ConverToHidlNotifyMessage(
89     const google_camera_hal::NotifyMessage& hal_message,
90     NotifyMsg* hidl_message);
91 
92 // Convert from HAL status_t to HIDL Status
93 // OK is converted to Status::OK.
94 // BAD_VALUE is converted to Status::ILLEGAL_ARGUMENT.
95 // -EBUSY is converted to Status::CAMERA_IN_USE.
96 // -EUSERS is converted to Status::MAX_CAMERAS_IN_USE.
97 // UNKNOWN_TRANSACTION is converted to Status::METHOD_NOT_SUPPORTED.
98 // INVALID_OPERATION is converted to Status::OPERATION_NOT_SUPPORTED.
99 // DEAD_OBJECT is converted to Status::CAMERA_DISCONNECTED.
100 // All other errors are converted to Status::INTERNAL_ERROR.
101 Status ConvertToHidlStatus(status_t hal_status);
102 
103 // Convert from HAL CameraDeviceStatus to HIDL CameraDeviceStatus
104 // kNotPresent is converted to CameraDeviceStatus::NOT_PRESENT.
105 // kPresent is converted to CameraDeviceStatus::PRESENT.
106 // kEnumerating is converted to CameraDeviceStatus::ENUMERATING.
107 status_t ConvertToHidlCameraDeviceStatus(
108     google_camera_hal::CameraDeviceStatus hal_camera_device_status,
109     CameraDeviceStatus* hidl_camera_device_status);
110 
111 // Convert from HAL TorchModeStatus to HIDL TorchModeStatus
112 // kNotAvailable is converted to TorchModeStatus::NOT_AVAILABLE.
113 // kAvailableOff is converted to TorchModeStatus::AVAILABLE_OFF.
114 // kAvailableOn is converted to TorchModeStatus::AVAILABLE_ON.
115 status_t ConvertToHidlTorchModeStatus(
116     google_camera_hal::TorchModeStatus hal_torch_status,
117     TorchModeStatus* hidl_torch_status);
118 
119 // Convert a HAL request to a HIDL request.
120 status_t ConvertToHidlBufferRequest(
121     const std::vector<google_camera_hal::BufferRequest>& hal_buffer_requests,
122     hidl_vec<BufferRequest>* hidl_buffer_requests);
123 
124 // Convert a HAL stream buffer to a HIDL hidl stream buffer.
125 status_t ConvertToHidlStreamBuffer(
126     const google_camera_hal::StreamBuffer& hal_buffer,
127     StreamBuffer* hidl_buffer);
128 
129 // Conversions from HIDL to HAL.
130 status_t ConvertToHalTemplateType(
131     RequestTemplate hidl_template,
132     google_camera_hal::RequestTemplate* hal_template);
133 
134 status_t ConvertToHalStreamBuffer(const StreamBuffer& hidl_buffer,
135                                   google_camera_hal::StreamBuffer* hal_buffer);
136 
137 status_t ConvertToHalMetadata(
138     uint32_t message_queue_setting_size,
139     MessageQueue<uint8_t, kSynchronizedReadWrite>* request_metadata_queue,
140     const CameraMetadata& request_settings,
141     std::unique_ptr<google_camera_hal::HalCameraMetadata>* hal_metadata);
142 
143 status_t ConvertToHalCaptureRequest(
144     const CaptureRequest& hidl_request,
145     MessageQueue<uint8_t, kSynchronizedReadWrite>* request_metadata_queue,
146     google_camera_hal::CaptureRequest* hal_request);
147 
148 status_t ConvertToHalBufferCaches(
149     const hidl_vec<BufferCache>& hidl_buffer_caches,
150     std::vector<google_camera_hal::BufferCache>* hal_buffer_caches);
151 
152 status_t ConverToHalStreamConfig(
153     const StreamConfiguration& hidl_stream_config,
154     google_camera_hal::StreamConfiguration* hal_stream_config);
155 
156 status_t ConverToHalStreamConfig(
157     const device::V3_4::StreamConfiguration& hidl_stream_config,
158     google_camera_hal::StreamConfiguration* hal_stream_config);
159 
160 status_t ConvertToHalStreamConfigurationMode(
161     StreamConfigurationMode hidl_mode,
162     google_camera_hal::StreamConfigurationMode* hal_mode);
163 
164 status_t ConvertToHalBufferStatus(BufferStatus hidl_status,
165                                   google_camera_hal::BufferStatus* hal_status);
166 
167 status_t ConvertToHalStream(const Stream& hidl_stream,
168                             google_camera_hal::Stream* hal_stream);
169 
170 status_t ConvertToHalStreamRotation(
171     StreamRotation hidl_stream_rotation,
172     google_camera_hal::StreamRotation* hal_stream_rotation);
173 
174 status_t ConvertToHalStreamType(StreamType hidl_stream_type,
175                                 google_camera_hal::StreamType* hal_stream_type);
176 
177 status_t ConvertToHalTorchMode(TorchMode hidl_torch_mode,
178                                google_camera_hal::TorchMode* hal_torch_mode);
179 
180 status_t ConvertToHalBufferRequestStatus(
181     const BufferRequestStatus& hidl_buffer_request_status,
182     google_camera_hal::BufferRequestStatus* hal_buffer_request_status);
183 
184 status_t ConvertToHalBufferReturnStatus(
185     const StreamBufferRet& hidl_stream_buffer_return,
186     google_camera_hal::BufferReturn* hal_buffer_return);
187 
188 status_t ConvertStreamConfigurationV34ToV37(
189     const device::V3_4::StreamConfiguration& config_3_4,
190     StreamConfiguration* config_3_7);
191 
192 }  // namespace hidl_utils
193 }  // namespace implementation
194 }  // namespace camera
195 }  // namespace hardware
196 }  // namespace android
197 
198 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_UTILS_H_
199