Iliyan Malchev | 41693fa | 2011-04-14 23:16:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010-2011 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 | // FIXME: add well-defined names for cameras |
| 18 | |
| 19 | #ifndef ANDROID_INCLUDE_CAMERA_H |
| 20 | #define ANDROID_INCLUDE_CAMERA_H |
| 21 | |
| 22 | #include <stdint.h> |
| 23 | #include <sys/cdefs.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <cutils/native_handle.h> |
| 26 | #include <system/camera.h> |
| 27 | #include <hardware/hardware.h> |
| 28 | #include <hardware/gralloc.h> |
| 29 | |
| 30 | __BEGIN_DECLS |
| 31 | |
| 32 | /** |
| 33 | * The id of this module |
| 34 | */ |
| 35 | #define CAMERA_HARDWARE_MODULE_ID "camera" |
| 36 | |
| 37 | struct camera_info { |
| 38 | /** |
| 39 | * The direction that the camera faces to. It should be CAMERA_FACING_BACK |
| 40 | * or CAMERA_FACING_FRONT. |
| 41 | */ |
| 42 | int facing; |
| 43 | |
| 44 | /** |
| 45 | * The orientation of the camera image. The value is the angle that the |
| 46 | * camera image needs to be rotated clockwise so it shows correctly on the |
| 47 | * display in its natural orientation. It should be 0, 90, 180, or 270. |
| 48 | * |
| 49 | * For example, suppose a device has a naturally tall screen. The |
| 50 | * back-facing camera sensor is mounted in landscape. You are looking at |
| 51 | * the screen. If the top side of the camera sensor is aligned with the |
| 52 | * right edge of the screen in natural orientation, the value should be |
| 53 | * 90. If the top side of a front-facing camera sensor is aligned with the |
| 54 | * right of the screen, the value should be 270. |
| 55 | */ |
| 56 | int orientation; |
| 57 | }; |
| 58 | |
| 59 | typedef struct camera_module { |
| 60 | hw_module_t common; |
| 61 | int (*get_number_of_cameras)(void); |
| 62 | int (*get_camera_info)(int camera_id, struct camera_info *info); |
| 63 | } camera_module_t; |
| 64 | |
Iliyan Malchev | 24b325e | 2011-06-06 16:39:06 -0700 | [diff] [blame] | 65 | struct camera_memory; |
| 66 | typedef void (*camera_release_memory)(struct camera_memory *mem); |
| 67 | |
Iliyan Malchev | 41693fa | 2011-04-14 23:16:54 -0700 | [diff] [blame] | 68 | typedef struct camera_memory { |
| 69 | void *data; |
| 70 | size_t size; |
| 71 | void *handle; |
Iliyan Malchev | 24b325e | 2011-06-06 16:39:06 -0700 | [diff] [blame] | 72 | camera_release_memory release; |
Iliyan Malchev | 41693fa | 2011-04-14 23:16:54 -0700 | [diff] [blame] | 73 | } camera_memory_t; |
| 74 | |
Iliyan Malchev | 24b325e | 2011-06-06 16:39:06 -0700 | [diff] [blame] | 75 | typedef camera_memory_t* (*camera_request_memory)(int fd, size_t buf_size, unsigned int num_bufs, |
| 76 | void *user); |
Iliyan Malchev | 41693fa | 2011-04-14 23:16:54 -0700 | [diff] [blame] | 77 | |
| 78 | typedef void (*camera_notify_callback)(int32_t msg_type, |
| 79 | int32_t ext1, |
| 80 | int32_t ext2, |
| 81 | void *user); |
| 82 | |
| 83 | typedef void (*camera_data_callback)(int32_t msg_type, |
Iliyan Malchev | 24b325e | 2011-06-06 16:39:06 -0700 | [diff] [blame] | 84 | const camera_memory_t *data, unsigned int index, |
Wu-cheng Li | 37ea6f7 | 2011-07-26 07:39:41 +0800 | [diff] [blame] | 85 | camera_frame_metadata_t *metadata, void *user); |
Iliyan Malchev | 41693fa | 2011-04-14 23:16:54 -0700 | [diff] [blame] | 86 | |
| 87 | typedef void (*camera_data_timestamp_callback)(int64_t timestamp, |
| 88 | int32_t msg_type, |
Iliyan Malchev | 24b325e | 2011-06-06 16:39:06 -0700 | [diff] [blame] | 89 | const camera_memory_t *data, unsigned int index, |
Iliyan Malchev | 41693fa | 2011-04-14 23:16:54 -0700 | [diff] [blame] | 90 | void *user); |
| 91 | |
| 92 | #define HAL_CAMERA_PREVIEW_WINDOW_TAG 0xcafed00d |
| 93 | |
| 94 | typedef struct preview_stream_ops { |
| 95 | int (*dequeue_buffer)(struct preview_stream_ops* w, |
Iliyan Malchev | 4deb188 | 2011-06-10 16:06:52 -0700 | [diff] [blame] | 96 | buffer_handle_t** buffer, int *stride); |
Iliyan Malchev | 41693fa | 2011-04-14 23:16:54 -0700 | [diff] [blame] | 97 | int (*enqueue_buffer)(struct preview_stream_ops* w, |
| 98 | buffer_handle_t* buffer); |
| 99 | int (*cancel_buffer)(struct preview_stream_ops* w, |
| 100 | buffer_handle_t* buffer); |
| 101 | int (*set_buffer_count)(struct preview_stream_ops* w, int count); |
| 102 | int (*set_buffers_geometry)(struct preview_stream_ops* pw, |
| 103 | int w, int h, int format); |
| 104 | int (*set_crop)(struct preview_stream_ops *w, |
| 105 | int left, int top, int right, int bottom); |
| 106 | int (*set_usage)(struct preview_stream_ops* w, int usage); |
| 107 | int (*set_swap_interval)(struct preview_stream_ops *w, int interval); |
Iliyan Malchev | 41693fa | 2011-04-14 23:16:54 -0700 | [diff] [blame] | 108 | int (*get_min_undequeued_buffer_count)(const struct preview_stream_ops *w, |
| 109 | int *count); |
Sundar Raman | ac0e067 | 2011-06-17 09:14:46 -0500 | [diff] [blame] | 110 | int (*lock_buffer)(struct preview_stream_ops* w, |
| 111 | buffer_handle_t* buffer); |
Eino-Ville Talvala | 7c50e9b | 2011-07-26 14:08:21 -0700 | [diff] [blame^] | 112 | // Timestamps are measured in nanoseconds, and must be comparable |
| 113 | // and monotonically increasing between two frames in the same |
| 114 | // preview stream. They do not need to be comparable between |
| 115 | // consecutive or parallel preview streams, cameras, or app runs. |
| 116 | int (*set_timestamp)(struct preview_stream_ops *w, int64_t timestamp); |
Iliyan Malchev | 41693fa | 2011-04-14 23:16:54 -0700 | [diff] [blame] | 117 | } preview_stream_ops_t; |
| 118 | |
| 119 | struct camera_device; |
| 120 | typedef struct camera_device_ops { |
| 121 | /** Set the ANativeWindow to which preview frames are sent */ |
| 122 | int (*set_preview_window)(struct camera_device *, |
| 123 | struct preview_stream_ops *window); |
| 124 | |
| 125 | /** Set the notification and data callbacks */ |
| 126 | void (*set_callbacks)(struct camera_device *, |
| 127 | camera_notify_callback notify_cb, |
| 128 | camera_data_callback data_cb, |
| 129 | camera_data_timestamp_callback data_cb_timestamp, |
| 130 | camera_request_memory get_memory, |
| 131 | void *user); |
| 132 | |
| 133 | /** |
| 134 | * The following three functions all take a msg_type, which is a bitmask of |
| 135 | * the messages defined in include/ui/Camera.h |
| 136 | */ |
| 137 | |
| 138 | /** |
| 139 | * Enable a message, or set of messages. |
| 140 | */ |
| 141 | void (*enable_msg_type)(struct camera_device *, int32_t msg_type); |
| 142 | |
| 143 | /** |
| 144 | * Disable a message, or a set of messages. |
| 145 | * |
| 146 | * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera |
| 147 | * HAL should not rely on its client to call releaseRecordingFrame() to |
| 148 | * release video recording frames sent out by the cameral HAL before and |
| 149 | * after the disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera HAL |
| 150 | * clients must not modify/access any video recording frame after calling |
| 151 | * disableMsgType(CAMERA_MSG_VIDEO_FRAME). |
| 152 | */ |
| 153 | void (*disable_msg_type)(struct camera_device *, int32_t msg_type); |
| 154 | |
| 155 | /** |
| 156 | * Query whether a message, or a set of messages, is enabled. Note that |
| 157 | * this is operates as an AND, if any of the messages queried are off, this |
| 158 | * will return false. |
| 159 | */ |
| 160 | int (*msg_type_enabled)(struct camera_device *, int32_t msg_type); |
| 161 | |
| 162 | /** |
| 163 | * Start preview mode. |
| 164 | */ |
| 165 | int (*start_preview)(struct camera_device *); |
| 166 | |
| 167 | /** |
| 168 | * Stop a previously started preview. |
| 169 | */ |
| 170 | void (*stop_preview)(struct camera_device *); |
| 171 | |
| 172 | /** |
| 173 | * Returns true if preview is enabled. |
| 174 | */ |
| 175 | int (*preview_enabled)(struct camera_device *); |
| 176 | |
| 177 | /** |
| 178 | * Request the camera HAL to store meta data or real YUV data in the video |
| 179 | * buffers sent out via CAMERA_MSG_VIDEO_FRAME for a recording session. If |
| 180 | * it is not called, the default camera HAL behavior is to store real YUV |
| 181 | * data in the video buffers. |
| 182 | * |
| 183 | * This method should be called before startRecording() in order to be |
| 184 | * effective. |
| 185 | * |
| 186 | * If meta data is stored in the video buffers, it is up to the receiver of |
| 187 | * the video buffers to interpret the contents and to find the actual frame |
| 188 | * data with the help of the meta data in the buffer. How this is done is |
| 189 | * outside of the scope of this method. |
| 190 | * |
| 191 | * Some camera HALs may not support storing meta data in the video buffers, |
| 192 | * but all camera HALs should support storing real YUV data in the video |
| 193 | * buffers. If the camera HAL does not support storing the meta data in the |
| 194 | * video buffers when it is requested to do do, INVALID_OPERATION must be |
| 195 | * returned. It is very useful for the camera HAL to pass meta data rather |
| 196 | * than the actual frame data directly to the video encoder, since the |
| 197 | * amount of the uncompressed frame data can be very large if video size is |
| 198 | * large. |
| 199 | * |
| 200 | * @param enable if true to instruct the camera HAL to store |
| 201 | * meta data in the video buffers; false to instruct |
| 202 | * the camera HAL to store real YUV data in the video |
| 203 | * buffers. |
| 204 | * |
| 205 | * @return OK on success. |
| 206 | */ |
| 207 | int (*store_meta_data_in_buffers)(struct camera_device *, int enable); |
| 208 | |
| 209 | /** |
| 210 | * Start record mode. When a record image is available, a |
| 211 | * CAMERA_MSG_VIDEO_FRAME message is sent with the corresponding |
| 212 | * frame. Every record frame must be released by a camera HAL client via |
| 213 | * releaseRecordingFrame() before the client calls |
| 214 | * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls |
| 215 | * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's |
| 216 | * responsibility to manage the life-cycle of the video recording frames, |
| 217 | * and the client must not modify/access any video recording frames. |
| 218 | */ |
| 219 | int (*start_recording)(struct camera_device *); |
| 220 | |
| 221 | /** |
| 222 | * Stop a previously started recording. |
| 223 | */ |
| 224 | void (*stop_recording)(struct camera_device *); |
| 225 | |
| 226 | /** |
| 227 | * Returns true if recording is enabled. |
| 228 | */ |
| 229 | int (*recording_enabled)(struct camera_device *); |
| 230 | |
| 231 | /** |
| 232 | * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME. |
| 233 | * |
| 234 | * It is camera HAL client's responsibility to release video recording |
| 235 | * frames sent out by the camera HAL before the camera HAL receives a call |
| 236 | * to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives the call to |
| 237 | * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's |
| 238 | * responsibility to manage the life-cycle of the video recording frames. |
| 239 | */ |
| 240 | void (*release_recording_frame)(struct camera_device *, |
| 241 | const void *opaque); |
| 242 | |
| 243 | /** |
| 244 | * Start auto focus, the notification callback routine is called with |
| 245 | * CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() will be |
| 246 | * called again if another auto focus is needed. |
| 247 | */ |
| 248 | int (*auto_focus)(struct camera_device *); |
| 249 | |
| 250 | /** |
| 251 | * Cancels auto-focus function. If the auto-focus is still in progress, |
| 252 | * this function will cancel it. Whether the auto-focus is in progress or |
| 253 | * not, this function will return the focus position to the default. If |
| 254 | * the camera does not support auto-focus, this is a no-op. |
| 255 | */ |
| 256 | int (*cancel_auto_focus)(struct camera_device *); |
| 257 | |
| 258 | /** |
| 259 | * Take a picture. |
| 260 | */ |
| 261 | int (*take_picture)(struct camera_device *); |
| 262 | |
| 263 | /** |
| 264 | * Cancel a picture that was started with takePicture. Calling this method |
| 265 | * when no picture is being taken is a no-op. |
| 266 | */ |
| 267 | int (*cancel_picture)(struct camera_device *); |
| 268 | |
| 269 | /** |
| 270 | * Set the camera parameters. This returns BAD_VALUE if any parameter is |
| 271 | * invalid or not supported. |
| 272 | */ |
| 273 | int (*set_parameters)(struct camera_device *, const char *parms); |
| 274 | |
Iliyan Malchev | 2280003 | 2011-07-26 15:47:56 -0700 | [diff] [blame] | 275 | /** Retrieve the camera parameters. The buffer returned by the camera HAL |
| 276 | must be returned back to it with put_parameters, if put_parameters |
| 277 | is not NULL. |
| 278 | */ |
Iliyan Malchev | 41693fa | 2011-04-14 23:16:54 -0700 | [diff] [blame] | 279 | char *(*get_parameters)(struct camera_device *); |
| 280 | |
Iliyan Malchev | 2280003 | 2011-07-26 15:47:56 -0700 | [diff] [blame] | 281 | /** The camera HAL uses its own memory to pass us the parameters when we |
| 282 | call get_parameters. Use this function to return the memory back to |
| 283 | the camera HAL, if put_parameters is not NULL. If put_parameters |
| 284 | is NULL, then you have to use free() to release the memory. |
| 285 | */ |
| 286 | void (*put_parameters)(struct camera_device *, char *); |
| 287 | |
Iliyan Malchev | 41693fa | 2011-04-14 23:16:54 -0700 | [diff] [blame] | 288 | /** |
| 289 | * Send command to camera driver. |
| 290 | */ |
| 291 | int (*send_command)(struct camera_device *, |
| 292 | int32_t cmd, int32_t arg1, int32_t arg2); |
| 293 | |
| 294 | /** |
| 295 | * Release the hardware resources owned by this object. Note that this is |
| 296 | * *not* done in the destructor. |
| 297 | */ |
| 298 | void (*release)(struct camera_device *); |
| 299 | |
| 300 | /** |
| 301 | * Dump state of the camera hardware |
| 302 | */ |
| 303 | int (*dump)(struct camera_device *, int fd); |
| 304 | } camera_device_ops_t; |
| 305 | |
| 306 | typedef struct camera_device { |
| 307 | hw_device_t common; |
| 308 | camera_device_ops_t *ops; |
| 309 | void *priv; |
| 310 | } camera_device_t; |
| 311 | |
| 312 | __END_DECLS |
| 313 | |
| 314 | #endif /* ANDROID_INCLUDE_CAMERA_H */ |