1 /* 2 * Copyright (C) 2022 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_AIDL_SERVICE_AIDL_UTILS_H_ 18 #define HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_UTILS_H_ 19 20 #include <aidl/android/hardware/camera/common/CameraMetadataType.h> 21 #include <aidl/android/hardware/camera/common/Status.h> 22 #include <aidl/android/hardware/camera/device/ICameraDevice.h> 23 #include <aidl/android/hardware/camera/provider/ICameraProvider.h> 24 #include <aidlcommonsupport/NativeHandle.h> 25 /*#include <android/hardware/camera/common/1.0/types.h> 26 #include <android/hardware/camera/device/3.7/ICameraDeviceSession.h> 27 #include <android/hardware/camera/device/3.8/types.h>*/ 28 #include <fmq/AidlMessageQueue.h> 29 #include <fmq/MessageQueue.h> 30 #include <hal_types.h> 31 32 #include <memory> 33 34 #include "aidl_camera_provider.h" 35 36 namespace android { 37 namespace hardware { 38 namespace camera { 39 namespace implementation { 40 namespace aidl_utils { 41 42 using aidl::android::hardware::camera::common::CameraDeviceStatus; 43 using aidl::android::hardware::camera::common::CameraMetadataType; 44 using aidl::android::hardware::camera::common::CameraResourceCost; 45 using aidl::android::hardware::camera::common::Status; 46 using aidl::android::hardware::camera::common::TorchModeStatus; 47 using aidl::android::hardware::camera::common::VendorTagSection; 48 using aidl::android::hardware::camera::device::BufferCache; 49 using aidl::android::hardware::camera::device::BufferRequest; 50 using aidl::android::hardware::camera::device::BufferRequestStatus; 51 using aidl::android::hardware::camera::device::BufferStatus; 52 using aidl::android::hardware::camera::device::CaptureRequest; 53 using aidl::android::hardware::camera::device::CaptureResult; 54 using aidl::android::hardware::camera::device::ConfigureStreamsRet; 55 using aidl::android::hardware::camera::device::ErrorCode; 56 using aidl::android::hardware::camera::device::ErrorMsg; 57 using aidl::android::hardware::camera::device::HalStream; 58 using aidl::android::hardware::camera::device::NotifyMsg; 59 using aidl::android::hardware::camera::device::RequestTemplate; 60 using aidl::android::hardware::camera::device::ShutterMsg; 61 using aidl::android::hardware::camera::device::Stream; 62 using aidl::android::hardware::camera::device::StreamBuffer; 63 using aidl::android::hardware::camera::device::StreamBufferRequestError; 64 using aidl::android::hardware::camera::device::StreamBufferRet; 65 using aidl::android::hardware::camera::device::StreamBuffersVal; 66 using aidl::android::hardware::camera::device::StreamConfiguration; 67 using aidl::android::hardware::camera::device::StreamConfigurationMode; 68 using aidl::android::hardware::camera::device::StreamRotation; 69 using aidl::android::hardware::camera::device::StreamType; 70 using aidl::android::hardware::camera::provider::ICameraProvider; 71 using aidl::android::hardware::common::NativeHandle; 72 using aidl::android::hardware::common::fmq::SynchronizedReadWrite; 73 74 using ndk::ScopedAStatus; 75 76 // Util functions to convert the types between AIDL and Google Camera HAL. 77 78 // Conversions from HAL to AIDL 79 80 ScopedAStatus ConvertToAidlReturn(status_t hal_status); 81 82 status_t ConvertToAidlVendorTagSections( 83 const std::vector<google_camera_hal::VendorTagSection>& hal_sections, 84 std::vector<VendorTagSection>* aidl_sections); 85 86 status_t ConvertToAidlVendorTagType( 87 google_camera_hal::CameraMetadataType hal_type, 88 CameraMetadataType* aidl_type); 89 90 status_t ConvertToAidlResourceCost( 91 const google_camera_hal::CameraResourceCost& hal_cost, 92 CameraResourceCost* aidl_cost); 93 94 status_t ConvertToAidlHalStreamConfig( 95 const google_camera_hal::ConfigureStreamsReturn& hal_config, 96 ConfigureStreamsRet* aidl_config); 97 98 status_t ConverToAidlNotifyMessage( 99 const google_camera_hal::NotifyMessage& hal_message, 100 NotifyMsg* aidl_message); 101 102 // Convert from HAL CameraDeviceStatus to AIDL CameraDeviceStatus 103 // kNotPresent is converted to CameraDeviceStatus::NOT_PRESENT. 104 // kPresent is converted to CameraDeviceStatus::PRESENT. 105 // kEnumerating is converted to CameraDeviceStatus::ENUMERATING. 106 status_t ConvertToAidlCameraDeviceStatus( 107 google_camera_hal::CameraDeviceStatus hal_camera_device_status, 108 CameraDeviceStatus* aidl_camera_device_status); 109 110 // Convert from HAL TorchModeStatus to AIDL TorchModeStatus 111 // kNotAvailable is converted to TorchModeStatus::NOT_AVAILABLE. 112 // kAvailableOff is converted to TorchModeStatus::AVAILABLE_OFF. 113 // kAvailableOn is converted to TorchModeStatus::AVAILABLE_ON. 114 status_t ConvertToAidlTorchModeStatus( 115 google_camera_hal::TorchModeStatus hal_torch_status, 116 TorchModeStatus* aidl_torch_status); 117 118 // Convert a HAL request to a AIDL request. 119 status_t ConvertToAidlBufferRequest( 120 const std::vector<google_camera_hal::BufferRequest>& hal_buffer_requests, 121 std::vector<BufferRequest>* aidl_buffer_requests); 122 123 status_t ConvertToHalBufferStatus(BufferStatus aidl_status, 124 google_camera_hal::BufferStatus* hal_status); 125 126 // Convert a HAL result to a AIDL result. It will try to write the result 127 // metadata to result_metadata_queue. If it fails, it will write the result 128 // metadata in aidl_result. 129 status_t ConvertToAidlCaptureResult( 130 AidlMessageQueue<int8_t, SynchronizedReadWrite>* result_metadata_queue, 131 std::unique_ptr<google_camera_hal::CaptureResult> hal_result, 132 CaptureResult* aidl_result); 133 134 // Convert a HAL stream buffer to a AIDL aidl stream buffer. 135 status_t ConvertToAidlStreamBuffer( 136 const google_camera_hal::StreamBuffer& hal_buffer, 137 StreamBuffer* aidl_buffer); 138 139 // Conversions from AIDL to HAL. 140 status_t ConvertToHalTemplateType( 141 RequestTemplate aidl_template, 142 google_camera_hal::RequestTemplate* hal_template); 143 144 bool IsAidlNativeHandleNull(const NativeHandle& handle); 145 146 status_t ConvertToHalStreamBuffer( 147 const StreamBuffer& aidl_buffer, google_camera_hal::StreamBuffer* hal_buffer, 148 std::vector<native_handle_t*>* handles_to_delete); 149 150 status_t ConvertToHalMetadata( 151 uint32_t message_queue_setting_size, 152 AidlMessageQueue<int8_t, SynchronizedReadWrite>* request_metadata_queue, 153 const std::vector<uint8_t>& request_settings, 154 std::unique_ptr<google_camera_hal::HalCameraMetadata>* hal_metadata); 155 156 status_t ConvertToHalCaptureRequest( 157 const CaptureRequest& aidl_request, 158 AidlMessageQueue<int8_t, SynchronizedReadWrite>* request_metadata_queue, 159 google_camera_hal::CaptureRequest* hal_request, 160 std::vector<native_handle_t*>* native_handles_to_delete); 161 162 status_t ConvertToHalBufferCaches( 163 const std::vector<BufferCache>& aidl_buffer_caches, 164 std::vector<google_camera_hal::BufferCache>* hal_buffer_caches); 165 166 // Optimize sensor pixel modes list: If all streams' sensor pixel modes 167 // list contains DEFAULT, just override them to DEFAULT only. 168 void FixSensorPixelModesInStreamConfig( 169 StreamConfiguration* out_aidl_stream_config); 170 171 status_t ConvertToHalStreamConfig( 172 const StreamConfiguration& aidl_stream_config, 173 google_camera_hal::StreamConfiguration* hal_stream_config); 174 175 status_t ConvertToHalStreamConfigurationMode( 176 StreamConfigurationMode aidl_mode, 177 google_camera_hal::StreamConfigurationMode* hal_mode); 178 179 status_t ConvertToHalStream(const Stream& aidl_stream, 180 google_camera_hal::Stream* hal_stream); 181 182 status_t ConvertToHalStreamRotation( 183 StreamRotation aidl_stream_rotation, 184 google_camera_hal::StreamRotation* hal_stream_rotation); 185 186 status_t ConvertToHalStreamType(StreamType aidl_stream_type, 187 google_camera_hal::StreamType* hal_stream_type); 188 189 status_t ConvertToHalBufferRequestStatus( 190 const BufferRequestStatus& aidl_buffer_request_status, 191 google_camera_hal::BufferRequestStatus* hal_buffer_request_status); 192 193 status_t ConvertToHalBufferReturnStatus( 194 const StreamBufferRet& aidl_stream_buffer_return, 195 google_camera_hal::BufferReturn* hal_buffer_return); 196 197 status_t ConvertToHalDeviceState( 198 const int64_t aidl_device_state, 199 google_camera_hal::DeviceState& hal_device_state); 200 201 } // namespace aidl_utils 202 } // namespace implementation 203 } // namespace camera 204 } // namespace hardware 205 } // namespace android 206 207 #endif // HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_UTILS_H_ 208