blob: 15b3b193b71e6f724a38dd24b05f7577752f0a48 [file] [log] [blame]
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -08001/*
2 * Copyright (C) 2012 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_COMMON_H
20#define ANDROID_INCLUDE_CAMERA_COMMON_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>
Ruben Brunk61cf9eb2014-01-14 15:27:58 -080027#include <system/camera_vendor_tags.h>
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080028#include <hardware/hardware.h>
29#include <hardware/gralloc.h>
30
31__BEGIN_DECLS
32
33/**
34 * The id of this module
35 */
36#define CAMERA_HARDWARE_MODULE_ID "camera"
37
38/**
39 * Module versioning information for the Camera hardware module, based on
40 * camera_module_t.common.module_api_version. The two most significant hex
41 * digits represent the major version, and the two least significant represent
42 * the minor version.
43 *
44 *******************************************************************************
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070045 * Versions: 0.X - 1.X [CAMERA_MODULE_API_VERSION_1_0]
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080046 *
47 * Camera modules that report these version numbers implement the initial
48 * camera module HAL interface. All camera devices openable through this
49 * module support only version 1 of the camera device HAL. The device_version
50 * and static_camera_characteristics fields of camera_info are not valid. Only
51 * the android.hardware.Camera API can be supported by this module and its
52 * devices.
53 *
54 *******************************************************************************
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070055 * Version: 2.0 [CAMERA_MODULE_API_VERSION_2_0]
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080056 *
57 * Camera modules that report this version number implement the second version
58 * of the camera module HAL interface. Camera devices openable through this
59 * module may support either version 1.0 or version 2.0 of the camera device
60 * HAL interface. The device_version field of camera_info is always valid; the
61 * static_camera_characteristics field of camera_info is valid if the
62 * device_version field is 2.0 or higher.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -080063 *
64 *******************************************************************************
65 * Version: 2.1 [CAMERA_MODULE_API_VERSION_2_1]
66 *
67 * This camera module version adds support for asynchronous callbacks to the
68 * framework from the camera HAL module, which is used to notify the framework
69 * about changes to the camera module state. Modules that provide a valid
70 * set_callbacks() method must report at least this version number.
Alex Ray19b2cea2013-06-13 12:40:52 -070071 *
72 *******************************************************************************
73 * Version: 2.2 [CAMERA_MODULE_API_VERSION_2_2]
74 *
75 * This camera module version adds vendor tag support from the module, and
76 * deprecates the old vendor_tag_query_ops that were previously only
77 * accessible with a device open.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080078 */
79
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070080/**
81 * Predefined macros for currently-defined version numbers
82 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080083
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070084/**
85 * All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
86 * as CAMERA_MODULE_API_VERSION_1_0
87 */
88#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
89#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -080090#define CAMERA_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1)
Alex Ray19b2cea2013-06-13 12:40:52 -070091#define CAMERA_MODULE_API_VERSION_2_2 HARDWARE_MODULE_API_VERSION(2, 2)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070092
Alex Ray19b2cea2013-06-13 12:40:52 -070093#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_2
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070094
95/**
96 * All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
97 * as CAMERA_DEVICE_API_VERSION_1_0
98 */
99#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
100#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800101#define CAMERA_DEVICE_API_VERSION_2_1 HARDWARE_DEVICE_API_VERSION(2, 1)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800102#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
Eino-Ville Talvala9d518562013-07-30 14:58:31 -0700103#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800104#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700105
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800106// Device version 2.x is outdated; device version 3.x is experimental
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700107#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_1_0
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800108
109/**
James Dongd0ca70d2012-03-26 16:22:35 -0700110 * Defined in /system/media/camera/include/system/camera_metadata.h
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800111 */
112typedef struct camera_metadata camera_metadata_t;
113
Alex Ray9acc7402013-02-07 15:44:24 -0800114typedef struct camera_info {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800115 /**
116 * The direction that the camera faces to. It should be CAMERA_FACING_BACK
117 * or CAMERA_FACING_FRONT.
118 *
119 * Version information:
120 * Valid in all camera_module versions
121 */
122 int facing;
123
124 /**
125 * The orientation of the camera image. The value is the angle that the
126 * camera image needs to be rotated clockwise so it shows correctly on the
127 * display in its natural orientation. It should be 0, 90, 180, or 270.
128 *
129 * For example, suppose a device has a naturally tall screen. The
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800130 * back-facing camera sensor is mounted in landscape. You are looking at the
131 * screen. If the top side of the camera sensor is aligned with the right
132 * edge of the screen in natural orientation, the value should be 90. If the
133 * top side of a front-facing camera sensor is aligned with the right of the
134 * screen, the value should be 270.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800135 *
136 * Version information:
137 * Valid in all camera_module versions
138 */
139 int orientation;
140
141 /**
142 * The value of camera_device_t.common.version.
143 *
144 * Version information (based on camera_module_t.common.module_api_version):
145 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700146 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800147 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700148 * Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800149 * not read this field.
150 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800151 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800152 *
153 * Always valid
154 *
155 */
156 uint32_t device_version;
157
158 /**
159 * The camera's fixed characteristics, which include all camera metadata in
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700160 * the android.*.info.* sections. This should be a sorted metadata buffer,
161 * and may not be modified or freed by the caller. The pointer should remain
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800162 * valid for the lifetime of the camera module, and values in it may not
163 * change after it is returned by get_camera_info().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800164 *
165 * Version information (based on camera_module_t.common.module_api_version):
166 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700167 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800168 *
169 * Not valid. Extra characteristics are not available. Do not read this
170 * field.
171 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800172 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800173 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700174 * Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
175 * otherwise.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800176 *
177 */
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700178 const camera_metadata_t *static_camera_characteristics;
Alex Ray9acc7402013-02-07 15:44:24 -0800179} camera_info_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800180
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800181/**
182 * camera_device_status_t:
183 *
184 * The current status of the camera device, as provided by the HAL through the
185 * camera_module_callbacks.camera_device_status_change() call.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700186 *
187 * At module load time, the framework will assume all camera devices are in the
188 * CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke
189 * camera_module_callbacks::camera_device_status_change to inform the framework
190 * of any initially NOT_PRESENT devices.
191 *
192 * Allowed transitions:
193 * PRESENT -> NOT_PRESENT
194 * NOT_PRESENT -> ENUMERATING
195 * NOT_PRESENT -> PRESENT
196 * ENUMERATING -> PRESENT
197 * ENUMERATING -> NOT_PRESENT
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800198 */
199typedef enum camera_device_status {
200 /**
201 * The camera device is not currently connected, and opening it will return
202 * failure. Calls to get_camera_info must still succeed, and provide the
203 * same information it would if the camera were connected
204 */
205 CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
206
207 /**
208 * The camera device is connected, and opening it will succeed. The
209 * information returned by get_camera_info cannot change due to this status
210 * change. By default, the framework will assume all devices are in this
211 * state.
212 */
Igor Murashkin152b50f2013-03-18 13:30:14 -0700213 CAMERA_DEVICE_STATUS_PRESENT = 1,
214
215 /**
216 * The camera device is connected, but it is undergoing an enumeration and
217 * so opening the device will return -EBUSY. Calls to get_camera_info
218 * must still succeed, as if the camera was in the PRESENT status.
219 */
220 CAMERA_DEVICE_STATUS_ENUMERATING = 2,
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800221
222} camera_device_status_t;
223
224/**
225 * Callback functions for the camera HAL module to use to inform the framework
226 * of changes to the camera subsystem. These are called only by HAL modules
227 * implementing version CAMERA_MODULE_API_VERSION_2_1 or higher of the HAL
228 * module API interface.
229 */
230typedef struct camera_module_callbacks {
231
232 /**
233 * camera_device_status_change:
234 *
235 * Callback to the framework to indicate that the state of a specific camera
236 * device has changed. At module load time, the framework will assume all
237 * camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
238 * must call this method to inform the framework of any initially
239 * NOT_PRESENT devices.
240 *
241 * camera_module_callbacks: The instance of camera_module_callbacks_t passed
242 * to the module with set_callbacks.
243 *
244 * camera_id: The ID of the camera device that has a new status.
245 *
246 * new_status: The new status code, one of the camera_device_status_t enums,
247 * or a platform-specific status.
248 *
249 */
250 void (*camera_device_status_change)(const struct camera_module_callbacks*,
251 int camera_id,
252 int new_status);
253
254} camera_module_callbacks_t;
255
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800256typedef struct camera_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700257 /**
258 * Common methods of the camera module. This *must* be the first member of
259 * camera_module as users of this structure will cast a hw_module_t to
260 * camera_module pointer in contexts where it's known the hw_module_t references a
261 * camera_module.
262 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800263 hw_module_t common;
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800264
265 /**
266 * get_number_of_cameras:
267 *
268 * Returns the number of camera devices accessible through the camera
269 * module. The camera devices are numbered 0 through N-1, where N is the
270 * value returned by this call. The name of the camera device for open() is
271 * simply the number converted to a string. That is, "0" for camera ID 0,
272 * "1" for camera ID 1.
273 *
274 * The value here must be static, and cannot change after the first call to
275 * this method
276 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800277 int (*get_number_of_cameras)(void);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800278
279 /**
280 * get_camera_info:
281 *
282 * Return the static camera information for a given camera device. This
283 * information may not change for a camera device.
284 *
285 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800286 int (*get_camera_info)(int camera_id, struct camera_info *info);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800287
288 /**
289 * set_callbacks:
290 *
291 * Provide callback function pointers to the HAL module to inform framework
292 * of asynchronous camera module events. The framework will call this
293 * function once after initial camera HAL module load, after the
294 * get_number_of_cameras() method is called for the first time, and before
295 * any other calls to the module.
296 *
297 * Version information (based on camera_module_t.common.module_api_version):
298 *
299 * CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
300 *
301 * Not provided by HAL module. Framework may not call this function.
302 *
303 * CAMERA_MODULE_API_VERSION_2_1:
304 *
305 * Valid to be called by the framework.
306 *
307 */
308 int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
309
Alex Ray19b2cea2013-06-13 12:40:52 -0700310 /**
311 * get_vendor_tag_ops:
312 *
313 * Get methods to query for vendor extension metadata tag information. The
314 * HAL should fill in all the vendor tag operation methods, or leave ops
315 * unchanged if no vendor tags are defined.
316 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800317 * The vendor_tag_ops structure used here is defined in:
318 * system/media/camera/include/system/vendor_tags.h
319 *
Alex Ray19b2cea2013-06-13 12:40:52 -0700320 * Version information (based on camera_module_t.common.module_api_version):
321 *
322 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1:
323 * Not provided by HAL module. Framework may not call this function.
324 *
325 * CAMERA_MODULE_API_VERSION_2_2:
326 * Valid to be called by the framework.
327 */
328 void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops);
329
330 /* reserved for future use */
331 void* reserved[8];
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800332} camera_module_t;
333
334__END_DECLS
335
336#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */