1 /* 2 * Copyright (C) 2016 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 ANDROID_VEHICLE_CAMERA_INTERFACE_H 18 #define ANDROID_VEHICLE_CAMERA_INTERFACE_H 19 20 #include <errno.h> 21 #include <stdint.h> 22 #include <sys/cdefs.h> 23 #include <sys/types.h> 24 25 #include <hardware/hardware.h> 26 #include <cutils/native_handle.h> 27 #include <system/window.h> 28 29 __BEGIN_DECLS 30 31 /*****************************************************************************/ 32 33 #define VEHICLE_CAMERA_HEADER_VERSION 1 34 #define VEHICLE_CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0) 35 #define VEHICLE_CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, VEHICLE_CAMERA_HEADER_VERSION) 36 37 /** 38 * Vehicle Camera to provide interfaces for controlling cameras 39 */ 40 41 /** 42 * The id of this module 43 */ 44 #define VEHICLE_CAMERA_HARDWARE_MODULE_ID "vehicle_camera" 45 46 /** 47 * Name of the vehicle device to open. Extend this list as 48 * more cameras are added. Each camera defined in vehicle_camera_type_t 49 * shall have a string defined for it. 50 */ 51 #define VEHICLE_CAMERA_RVC_DEVICE "vehicle_camera_rvc_device" 52 53 /** 54 * Each camera on the car shall be enumerated 55 */ 56 typedef enum { 57 VEHICLE_CAMERA_RVC = 1, 58 } vehicle_camera_type_t; 59 60 /** 61 * Describes the current state of camera device 62 */ 63 typedef struct { 64 uint32_t overlay_on; 65 uint32_t camera_on; 66 } vehicle_camera_state_t; 67 68 /** 69 * Bitmask of features supported by a camera module 70 */ 71 enum { 72 VEHICLE_CAMERA_CONFIG_FLAG_ANDROID_OVERLAY_SUPPORT = 0x1, 73 VEHICLE_CAMERA_CONFIG_FLAG_CAMERA_CROP_SUPPORT = 0x2, 74 VEHICLE_CAMERA_CONFIG_FLAG_CAMERA_POSITIONING_SUPPORT = 0x4 75 } vehicle_camera_config_flag; 76 77 typedef struct { 78 uint32_t capabilites_flags; 79 uint32_t camera_width; 80 uint32_t camera_height; 81 uint32_t display_width; 82 uint32_t display_height; 83 } vehicle_camera_cap_t; 84 85 /************************************************************************************/ 86 87 /** 88 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 89 * and the fields of this data structure must begin with hw_module_t 90 * followed by module specific information. 91 */ 92 typedef struct { 93 struct hw_module_t common; 94 /** 95 * Queries the HW for the cameras installed on the vehicle 96 * @param num_cameras - number of camera devices available. If 97 * 0 is returned, an error has occurred and 98 * the return pointer shall be NULL. 99 * @return pointer to an array of vehicle_camera_type_t to 100 * denote which cameras are installed. This pointer is 101 * only valid while the vehicle hal is loaded. If the 102 * pointer is NULL, then an error has occurred and 103 * num_cameras shall be 0. 104 */ 105 const uint32_t * (*get_camera_device_list)(uint32_t *num_cameras); 106 } vehicle_camera_module_t; 107 108 109 typedef struct vehicle_camera_device_t { 110 struct hw_device_t common; 111 112 const uint32_t camera_type; 113 114 /** 115 * Returns the capabilities of this camera. 116 * @param device - device handle 117 * @param cap - pointer to capabilities flags being returned 118 * @return 0 on success 119 * -EPERM if device is invalid or not initialized 120 */ 121 int (*get_capabilities)(struct vehicle_camera_device_t *device, vehicle_camera_cap_t *cap); 122 123 /** 124 * Gets the current camera crop settings. 125 * @param device - device handle 126 * @param rect - current camera crop settings 127 * @return 0 on success 128 * -EPERM if device is not initialized 129 * -errno on error 130 */ 131 int (*get_camera_crop)(struct vehicle_camera_device_t *device, android_native_rect_t *rect); 132 133 /** 134 * Sets the camera crop. 135 * @param device - device handle 136 * @param rect - area of camera input to crop. Must fit within 137 * camera width and height from camera capabilities. 138 * @return 0 on success 139 * -EPERM if device is not initialized 140 * -errno on error 141 */ 142 int (*set_camera_crop)(struct vehicle_camera_device_t *device, const android_native_rect_t *rect); 143 144 /** 145 * Gets position of the camera on the display. 146 * @param device - device handle 147 * @param rect - area of display the camera will appear when on 148 * @return 0 on success 149 * -EPERM if device is not initialized 150 * -errno on error 151 */ 152 int (*get_camera_position)(struct vehicle_camera_device_t *device, android_native_rect_t *rect); 153 154 /** 155 * Sets position of the camera on the display. 156 * @param device - device handle 157 * @param rect - area of display the camera will appear when on. 158 * Must fit within display width and height from 159 * camera capabilities. 160 * @return 0 on success 161 * -EPERM if device is not initialized 162 * -errno on error 163 */ 164 int (*set_camera_position)(struct vehicle_camera_device_t *device, const android_native_rect_t *rect); 165 166 /** 167 * Gets the current camera state. 168 * @param device - device handle 169 * @param state - last setting for the camera 170 * @return 0 on success 171 * -EPERM if device is not initialized 172 */ 173 int (*get_camera_state)(struct vehicle_camera_device_t *device, vehicle_camera_state_t *state); 174 175 /** 176 * Sets the camera state. 177 * @param device - device handle 178 * @param state - desired setting for the camera 179 * @return 0 on success 180 * -EPERM if device is not initialized 181 * -errno on error 182 */ 183 int (*set_camera_state)(struct vehicle_camera_device_t *device, const vehicle_camera_state_t *state); 184 } vehicle_camera_device_t; 185 186 __END_DECLS 187 188 #endif // ANDROID_VEHICLE_CAMERA_INTERFACE_H 189