blob: 322ed93fb75a4a838f2b52cc85f894784c0bceb2 [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.
Zhijun Hebcdebf32014-06-06 15:42:17 -070078 *
79 *******************************************************************************
80 * Version: 2.3 [CAMERA_MODULE_API_VERSION_2_3]
81 *
82 * This camera module version adds open legacy camera HAL device support.
83 * Framework can use it to open the camera device as lower device HAL version
84 * HAL device if the same device can support multiple device API versions.
85 * The standard hardware module open call (common.methods->open) continues
86 * to open the camera device with the latest supported version, which is
87 * also the version listed in camera_info_t.device_version.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080088 */
89
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070090/**
91 * Predefined macros for currently-defined version numbers
92 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080093
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070094/**
95 * All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
96 * as CAMERA_MODULE_API_VERSION_1_0
97 */
98#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
99#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800100#define CAMERA_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1)
Alex Ray19b2cea2013-06-13 12:40:52 -0700101#define CAMERA_MODULE_API_VERSION_2_2 HARDWARE_MODULE_API_VERSION(2, 2)
Zhijun Hebcdebf32014-06-06 15:42:17 -0700102#define CAMERA_MODULE_API_VERSION_2_3 HARDWARE_MODULE_API_VERSION(2, 3)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700103
Zhijun Hebcdebf32014-06-06 15:42:17 -0700104#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_3
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700105
106/**
107 * All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
108 * as CAMERA_DEVICE_API_VERSION_1_0
109 */
110#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
111#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800112#define CAMERA_DEVICE_API_VERSION_2_1 HARDWARE_DEVICE_API_VERSION(2, 1)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800113#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
Eino-Ville Talvala9d518562013-07-30 14:58:31 -0700114#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800115#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700116
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800117// Device version 2.x is outdated; device version 3.x is experimental
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700118#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_1_0
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800119
120/**
James Dongd0ca70d2012-03-26 16:22:35 -0700121 * Defined in /system/media/camera/include/system/camera_metadata.h
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800122 */
123typedef struct camera_metadata camera_metadata_t;
124
Alex Ray9acc7402013-02-07 15:44:24 -0800125typedef struct camera_info {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800126 /**
127 * The direction that the camera faces to. It should be CAMERA_FACING_BACK
128 * or CAMERA_FACING_FRONT.
129 *
130 * Version information:
131 * Valid in all camera_module versions
132 */
133 int facing;
134
135 /**
136 * The orientation of the camera image. The value is the angle that the
137 * camera image needs to be rotated clockwise so it shows correctly on the
138 * display in its natural orientation. It should be 0, 90, 180, or 270.
139 *
140 * For example, suppose a device has a naturally tall screen. The
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800141 * back-facing camera sensor is mounted in landscape. You are looking at the
142 * screen. If the top side of the camera sensor is aligned with the right
143 * edge of the screen in natural orientation, the value should be 90. If the
144 * top side of a front-facing camera sensor is aligned with the right of the
145 * screen, the value should be 270.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800146 *
147 * Version information:
148 * Valid in all camera_module versions
149 */
150 int orientation;
151
152 /**
153 * The value of camera_device_t.common.version.
154 *
155 * Version information (based on camera_module_t.common.module_api_version):
156 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700157 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800158 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700159 * Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800160 * not read this field.
161 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800162 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800163 *
164 * Always valid
165 *
166 */
167 uint32_t device_version;
168
169 /**
170 * The camera's fixed characteristics, which include all camera metadata in
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700171 * the android.*.info.* sections. This should be a sorted metadata buffer,
172 * and may not be modified or freed by the caller. The pointer should remain
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800173 * valid for the lifetime of the camera module, and values in it may not
174 * change after it is returned by get_camera_info().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800175 *
176 * Version information (based on camera_module_t.common.module_api_version):
177 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700178 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800179 *
180 * Not valid. Extra characteristics are not available. Do not read this
181 * field.
182 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800183 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800184 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700185 * Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
186 * otherwise.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800187 *
188 */
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700189 const camera_metadata_t *static_camera_characteristics;
Alex Ray9acc7402013-02-07 15:44:24 -0800190} camera_info_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800191
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800192/**
193 * camera_device_status_t:
194 *
195 * The current status of the camera device, as provided by the HAL through the
196 * camera_module_callbacks.camera_device_status_change() call.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700197 *
198 * At module load time, the framework will assume all camera devices are in the
199 * CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke
200 * camera_module_callbacks::camera_device_status_change to inform the framework
201 * of any initially NOT_PRESENT devices.
202 *
203 * Allowed transitions:
204 * PRESENT -> NOT_PRESENT
205 * NOT_PRESENT -> ENUMERATING
206 * NOT_PRESENT -> PRESENT
207 * ENUMERATING -> PRESENT
208 * ENUMERATING -> NOT_PRESENT
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800209 */
210typedef enum camera_device_status {
211 /**
212 * The camera device is not currently connected, and opening it will return
213 * failure. Calls to get_camera_info must still succeed, and provide the
214 * same information it would if the camera were connected
215 */
216 CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
217
218 /**
219 * The camera device is connected, and opening it will succeed. The
220 * information returned by get_camera_info cannot change due to this status
221 * change. By default, the framework will assume all devices are in this
222 * state.
223 */
Igor Murashkin152b50f2013-03-18 13:30:14 -0700224 CAMERA_DEVICE_STATUS_PRESENT = 1,
225
226 /**
227 * The camera device is connected, but it is undergoing an enumeration and
228 * so opening the device will return -EBUSY. Calls to get_camera_info
229 * must still succeed, as if the camera was in the PRESENT status.
230 */
231 CAMERA_DEVICE_STATUS_ENUMERATING = 2,
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800232
233} camera_device_status_t;
234
235/**
236 * Callback functions for the camera HAL module to use to inform the framework
237 * of changes to the camera subsystem. These are called only by HAL modules
238 * implementing version CAMERA_MODULE_API_VERSION_2_1 or higher of the HAL
239 * module API interface.
240 */
241typedef struct camera_module_callbacks {
242
243 /**
244 * camera_device_status_change:
245 *
246 * Callback to the framework to indicate that the state of a specific camera
247 * device has changed. At module load time, the framework will assume all
248 * camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
249 * must call this method to inform the framework of any initially
250 * NOT_PRESENT devices.
251 *
252 * camera_module_callbacks: The instance of camera_module_callbacks_t passed
253 * to the module with set_callbacks.
254 *
255 * camera_id: The ID of the camera device that has a new status.
256 *
257 * new_status: The new status code, one of the camera_device_status_t enums,
258 * or a platform-specific status.
259 *
260 */
261 void (*camera_device_status_change)(const struct camera_module_callbacks*,
262 int camera_id,
263 int new_status);
264
265} camera_module_callbacks_t;
266
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800267typedef struct camera_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700268 /**
269 * Common methods of the camera module. This *must* be the first member of
270 * camera_module as users of this structure will cast a hw_module_t to
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700271 * camera_module pointer in contexts where it's known the hw_module_t
272 * references a camera_module.
273 *
274 * The return values for common.methods->open for camera_module are:
275 *
276 * 0: On a successful open of the camera device.
277 *
278 * -ENODEV: The camera device cannot be opened due to an internal
279 * error.
280 *
281 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
282 * and/or the module is invalid.
283 *
284 * -EBUSY: The camera device was already opened for this camera id
285 * (by using this method or open_legacy),
286 * regardless of the device HAL version it was opened as.
287 *
288 * -EUSERS: The maximal number of camera devices that can be
289 * opened concurrently were opened already, either by
290 * this method or the open_legacy method.
291 *
292 * All other return values from common.methods->open will be treated as
293 * -ENODEV.
Stewart Miles84d35492014-05-01 09:03:27 -0700294 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800295 hw_module_t common;
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800296
297 /**
298 * get_number_of_cameras:
299 *
300 * Returns the number of camera devices accessible through the camera
301 * module. The camera devices are numbered 0 through N-1, where N is the
302 * value returned by this call. The name of the camera device for open() is
303 * simply the number converted to a string. That is, "0" for camera ID 0,
304 * "1" for camera ID 1.
305 *
306 * The value here must be static, and cannot change after the first call to
307 * this method
308 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800309 int (*get_number_of_cameras)(void);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800310
311 /**
312 * get_camera_info:
313 *
314 * Return the static camera information for a given camera device. This
315 * information may not change for a camera device.
316 *
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700317 * Return values:
318 *
319 * 0: On a successful operation
320 *
321 * -ENODEV: The information cannot be provided due to an internal
322 * error.
323 *
324 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
325 * and/or the module is invalid.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800326 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800327 int (*get_camera_info)(int camera_id, struct camera_info *info);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800328
329 /**
330 * set_callbacks:
331 *
332 * Provide callback function pointers to the HAL module to inform framework
333 * of asynchronous camera module events. The framework will call this
334 * function once after initial camera HAL module load, after the
335 * get_number_of_cameras() method is called for the first time, and before
336 * any other calls to the module.
337 *
338 * Version information (based on camera_module_t.common.module_api_version):
339 *
340 * CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
341 *
342 * Not provided by HAL module. Framework may not call this function.
343 *
344 * CAMERA_MODULE_API_VERSION_2_1:
345 *
346 * Valid to be called by the framework.
347 *
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700348 * Return values:
349 *
350 * 0: On a successful operation
351 *
352 * -ENODEV: The operation cannot be completed due to an internal
353 * error.
354 *
355 * -EINVAL: The input arguments are invalid, i.e. the callbacks are
356 * null
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800357 */
358 int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
359
Alex Ray19b2cea2013-06-13 12:40:52 -0700360 /**
361 * get_vendor_tag_ops:
362 *
363 * Get methods to query for vendor extension metadata tag information. The
364 * HAL should fill in all the vendor tag operation methods, or leave ops
365 * unchanged if no vendor tags are defined.
366 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800367 * The vendor_tag_ops structure used here is defined in:
368 * system/media/camera/include/system/vendor_tags.h
369 *
Alex Ray19b2cea2013-06-13 12:40:52 -0700370 * Version information (based on camera_module_t.common.module_api_version):
371 *
372 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1:
373 * Not provided by HAL module. Framework may not call this function.
374 *
375 * CAMERA_MODULE_API_VERSION_2_2:
376 * Valid to be called by the framework.
377 */
378 void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops);
379
Zhijun Hebcdebf32014-06-06 15:42:17 -0700380 /**
381 * open_legacy:
382 *
383 * Open a specific legacy camera HAL device if multiple device HAL API
384 * versions are supported by this camera HAL module. For example, if the
385 * camera module supports both CAMERA_DEVICE_API_VERSION_1_0 and
386 * CAMERA_DEVICE_API_VERSION_3_2 device API for the same camera id,
387 * framework can call this function to open the camera device as
388 * CAMERA_DEVICE_API_VERSION_1_0 device.
389 *
390 * This is an optional method. A Camera HAL module does not need to support
391 * more than one device HAL version per device, and such modules may return
392 * -ENOSYS for all calls to this method. For all older HAL device API
393 * versions that are not supported, it may return -EOPNOTSUPP. When above
394 * cases occur, The normal open() method (common.methods->open) will be
395 * used by the framework instead.
396 *
397 * Version information (based on camera_module_t.common.module_api_version):
398 *
399 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2:
400 * Not provided by HAL module. Framework will not call this function.
401 *
402 * CAMERA_MODULE_API_VERSION_2_3:
403 * Valid to be called by the framework.
404 *
405 * Return values:
406 *
407 * 0: On a successful open of the camera device.
408 *
409 * -ENOSYS This method is not supported.
410 *
411 * -EOPNOTSUPP: The requested HAL version is not supported by this method.
412 *
413 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
414 * and/or the module is invalid.
415 *
416 * -EBUSY: The camera device was already opened for this camera id
417 * (by using this method or common.methods->open method),
418 * regardless of the device HAL version it was opened as.
419 *
420 * -EUSERS: The maximal number of camera devices that can be
421 * opened concurrently were opened already, either by
422 * this method or common.methods->open method.
423 */
424 int (*open_legacy)(const struct hw_module_t* module, const char* id,
425 uint32_t halVersion, struct hw_device_t** device);
426
Alex Ray19b2cea2013-06-13 12:40:52 -0700427 /* reserved for future use */
Zhijun Hebcdebf32014-06-06 15:42:17 -0700428 void* reserved[7];
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800429} camera_module_t;
430
431__END_DECLS
432
433#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */