blob: c2d4536f60d453b27100f6914d286b6529c0ffdb [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>
Chien-Yu Chen30159172015-01-08 11:06:38 -080023#include <stdbool.h>
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080024#include <sys/cdefs.h>
25#include <sys/types.h>
26#include <cutils/native_handle.h>
27#include <system/camera.h>
Ruben Brunk61cf9eb2014-01-14 15:27:58 -080028#include <system/camera_vendor_tags.h>
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080029#include <hardware/hardware.h>
30#include <hardware/gralloc.h>
31
32__BEGIN_DECLS
33
34/**
35 * The id of this module
36 */
37#define CAMERA_HARDWARE_MODULE_ID "camera"
38
39/**
40 * Module versioning information for the Camera hardware module, based on
41 * camera_module_t.common.module_api_version. The two most significant hex
42 * digits represent the major version, and the two least significant represent
43 * the minor version.
44 *
45 *******************************************************************************
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070046 * Versions: 0.X - 1.X [CAMERA_MODULE_API_VERSION_1_0]
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080047 *
48 * Camera modules that report these version numbers implement the initial
49 * camera module HAL interface. All camera devices openable through this
50 * module support only version 1 of the camera device HAL. The device_version
51 * and static_camera_characteristics fields of camera_info are not valid. Only
52 * the android.hardware.Camera API can be supported by this module and its
53 * devices.
54 *
55 *******************************************************************************
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070056 * Version: 2.0 [CAMERA_MODULE_API_VERSION_2_0]
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080057 *
58 * Camera modules that report this version number implement the second version
59 * of the camera module HAL interface. Camera devices openable through this
60 * module may support either version 1.0 or version 2.0 of the camera device
61 * HAL interface. The device_version field of camera_info is always valid; the
62 * static_camera_characteristics field of camera_info is valid if the
63 * device_version field is 2.0 or higher.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -080064 *
65 *******************************************************************************
66 * Version: 2.1 [CAMERA_MODULE_API_VERSION_2_1]
67 *
68 * This camera module version adds support for asynchronous callbacks to the
69 * framework from the camera HAL module, which is used to notify the framework
70 * about changes to the camera module state. Modules that provide a valid
71 * set_callbacks() method must report at least this version number.
Alex Ray19b2cea2013-06-13 12:40:52 -070072 *
73 *******************************************************************************
74 * Version: 2.2 [CAMERA_MODULE_API_VERSION_2_2]
75 *
76 * This camera module version adds vendor tag support from the module, and
77 * deprecates the old vendor_tag_query_ops that were previously only
78 * accessible with a device open.
Zhijun Hebcdebf32014-06-06 15:42:17 -070079 *
80 *******************************************************************************
81 * Version: 2.3 [CAMERA_MODULE_API_VERSION_2_3]
82 *
83 * This camera module version adds open legacy camera HAL device support.
84 * Framework can use it to open the camera device as lower device HAL version
85 * HAL device if the same device can support multiple device API versions.
86 * The standard hardware module open call (common.methods->open) continues
87 * to open the camera device with the latest supported version, which is
88 * also the version listed in camera_info_t.device_version.
Chien-Yu Chen30159172015-01-08 11:06:38 -080089 *
90 *******************************************************************************
91 * Version: 2.4 [CAMERA_MODULE_API_VERSION_2_4]
92 *
Zhijun He94e23b22015-01-12 14:45:33 -080093 * This camera module version adds below API changes:
94 *
95 * 1. Torch mode support. The framework can use it to turn on torch mode for
96 * any camera device that has a flash unit, without opening a camera device. The
97 * camera device has a higher priority accessing the flash unit than the camera
98 * module; opening a camera device will turn off the torch if it had been enabled
99 * through the module interface. When there are any resource conflicts, such as
100 * open() is called to open a camera device, the camera HAL module must notify the
101 * framework through the torch mode status callback that the torch mode has been
102 * turned off.
103 *
104 * 2. External camera (e.g. USB hot-plug camera) support. The API updates specify that
105 * the camera static info is only available when camera is connected and ready to
106 * use for external hot-plug cameras. Calls to get static info will be invalid
107 * calls when camera status is not CAMERA_DEVICE_STATUS_PRESENT. The frameworks
108 * will only count on device status change callbacks to manage the available external
109 * camera list.
Ruben Brunk0388bcd2015-01-16 14:29:21 -0800110 *
111 * 3. Camera arbitration hints. This module version adds support for explicitly
112 * indicating the number of camera devices that can be simultaneously opened and used.
113 * To specify valid combinations of devices, the resource_cost and conflicting_devices
114 * fields should always be set in the camera_info structure returned by the
115 * get_camera_info call.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800116 */
117
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700118/**
119 * Predefined macros for currently-defined version numbers
120 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800121
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700122/**
123 * All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
124 * as CAMERA_MODULE_API_VERSION_1_0
125 */
126#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
127#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800128#define CAMERA_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1)
Alex Ray19b2cea2013-06-13 12:40:52 -0700129#define CAMERA_MODULE_API_VERSION_2_2 HARDWARE_MODULE_API_VERSION(2, 2)
Zhijun Hebcdebf32014-06-06 15:42:17 -0700130#define CAMERA_MODULE_API_VERSION_2_3 HARDWARE_MODULE_API_VERSION(2, 3)
Chien-Yu Chen30159172015-01-08 11:06:38 -0800131#define CAMERA_MODULE_API_VERSION_2_4 HARDWARE_MODULE_API_VERSION(2, 4)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700132
Chien-Yu Chen30159172015-01-08 11:06:38 -0800133#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_4
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700134
135/**
136 * All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
137 * as CAMERA_DEVICE_API_VERSION_1_0
138 */
139#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
140#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800141#define CAMERA_DEVICE_API_VERSION_2_1 HARDWARE_DEVICE_API_VERSION(2, 1)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800142#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
Eino-Ville Talvala9d518562013-07-30 14:58:31 -0700143#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800144#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
Zhijun Heebdf1282015-01-16 16:44:40 -0800145#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700146
Zhijun Heebdf1282015-01-16 16:44:40 -0800147// Device version 3.3 is current, older HAL camera device versions are not
Eino-Ville Talvalab5459832014-09-09 16:42:27 -0700148// recommended for new devices.
Zhijun Heebdf1282015-01-16 16:44:40 -0800149#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_3_3
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800150
151/**
James Dongd0ca70d2012-03-26 16:22:35 -0700152 * Defined in /system/media/camera/include/system/camera_metadata.h
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800153 */
154typedef struct camera_metadata camera_metadata_t;
155
Alex Ray9acc7402013-02-07 15:44:24 -0800156typedef struct camera_info {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800157 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800158 * The direction that the camera faces to. See system/core/include/system/camera.h
159 * for camera facing definitions.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800160 *
Zhijun He94e23b22015-01-12 14:45:33 -0800161 * Version information (based on camera_module_t.common.module_api_version):
162 *
163 * CAMERA_MODULE_API_VERSION_2_3 or lower:
164 *
165 * It should be CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
166 *
167 * CAMERA_MODULE_API_VERSION_2_4 or higher:
168 *
169 * It should be CAMERA_FACING_BACK, CAMERA_FACING_FRONT or
170 * CAMERA_FACING_EXTERNAL.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800171 */
172 int facing;
173
174 /**
175 * The orientation of the camera image. The value is the angle that the
176 * camera image needs to be rotated clockwise so it shows correctly on the
177 * display in its natural orientation. It should be 0, 90, 180, or 270.
178 *
179 * For example, suppose a device has a naturally tall screen. The
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800180 * back-facing camera sensor is mounted in landscape. You are looking at the
181 * screen. If the top side of the camera sensor is aligned with the right
182 * edge of the screen in natural orientation, the value should be 90. If the
183 * top side of a front-facing camera sensor is aligned with the right of the
184 * screen, the value should be 270.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800185 *
Zhijun He94e23b22015-01-12 14:45:33 -0800186 * Version information (based on camera_module_t.common.module_api_version):
187 *
188 * CAMERA_MODULE_API_VERSION_2_3 or lower:
189 *
190 * Valid in all camera_module versions.
191 *
192 * CAMERA_MODULE_API_VERSION_2_4 or higher:
193 *
194 * Valid if camera facing is CAMERA_FACING_BACK or CAMERA_FACING_FRONT,
195 * not valid if camera facing is CAMERA_FACING_EXTERNAL.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800196 */
197 int orientation;
198
199 /**
200 * The value of camera_device_t.common.version.
201 *
202 * Version information (based on camera_module_t.common.module_api_version):
203 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700204 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800205 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700206 * Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800207 * not read this field.
208 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800209 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800210 *
211 * Always valid
212 *
213 */
214 uint32_t device_version;
215
216 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800217 * The camera's fixed characteristics, which include all static camera metadata
218 * specified in system/media/camera/docs/docs.html. This should be a sorted metadata
219 * buffer, and may not be modified or freed by the caller. The pointer should remain
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800220 * valid for the lifetime of the camera module, and values in it may not
221 * change after it is returned by get_camera_info().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800222 *
223 * Version information (based on camera_module_t.common.module_api_version):
224 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700225 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800226 *
227 * Not valid. Extra characteristics are not available. Do not read this
228 * field.
229 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800230 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800231 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700232 * Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
233 * otherwise.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800234 *
235 */
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700236 const camera_metadata_t *static_camera_characteristics;
Ruben Brunk0388bcd2015-01-16 14:29:21 -0800237
238 /**
Ruben Brunk1fa09022015-03-10 11:53:12 -0700239 * The total resource "cost" of using this camera, represented as an integer
240 * value in the range [0, 100] where 100 represents total usage of the shared
241 * resource that is the limiting bottleneck of the camera subsystem. This may
242 * be a very rough estimate, and is used as a hint to the camera service to
243 * determine when to disallow multiple applications from simultaneously
244 * opening different cameras advertised by the camera service.
Ruben Brunk0388bcd2015-01-16 14:29:21 -0800245 *
246 * The camera service must be able to simultaneously open and use any
247 * combination of camera devices exposed by the HAL where the sum of
248 * the resource costs of these cameras is <= 100. For determining cost,
249 * each camera device must be assumed to be configured and operating at
250 * the maximally resource-consuming framerate and stream size settings
251 * available in the configuration settings exposed for that device through
252 * the camera metadata.
253 *
Ruben Brunk1fa09022015-03-10 11:53:12 -0700254 * The camera service may still attempt to simultaneously open combinations
255 * of camera devices with a total resource cost > 100. This may succeed or
256 * fail. If this succeeds, combinations of configurations that are not
257 * supported due to resource constraints from having multiple open devices
258 * should fail during the configure calls. If the total resource cost is
259 * <= 100, open and configure should never fail for any stream configuration
260 * settings or other device capabilities that would normally succeed for a
261 * device when it is the only open camera device.
262 *
263 * This field will be used to determine whether background applications are
264 * allowed to use this camera device while other applications are using other
265 * camera devices. Note: multiple applications will never be allowed by the
266 * camera service to simultaneously open the same camera device.
267 *
268 * Example use cases:
269 *
270 * Ex. 1: Camera Device 0 = Back Camera
271 * Camera Device 1 = Front Camera
272 * - Using both camera devices causes a large framerate slowdown due to
273 * limited ISP bandwidth.
274 *
275 * Configuration:
276 *
277 * Camera Device 0 - resource_cost = 51
278 * conflicting_devices = null
279 * Camera Device 1 - resource_cost = 51
280 * conflicting_devices = null
281 *
282 * Result:
283 *
284 * Since the sum of the resource costs is > 100, if a higher-priority
285 * application has either device open, no lower-priority applications will be
286 * allowed by the camera service to open either device. If a lower-priority
287 * application is using a device that a higher-priority subsequently attempts
288 * to open, the lower-priority application will be forced to disconnect the
289 * the device.
290 *
291 * If the highest-priority application chooses, it may still attempt to open
292 * both devices (since these devices are not listed as conflicting in the
293 * conflicting_devices fields), but usage of these devices may fail in the
294 * open or configure calls.
295 *
296 * Ex. 2: Camera Device 0 = Left Back Camera
297 * Camera Device 1 = Right Back Camera
298 * Camera Device 2 = Combined stereo camera using both right and left
299 * back camera sensors used by devices 0, and 1
300 * Camera Device 3 = Front Camera
301 * - Due to do hardware constraints, up to two cameras may be open at once. The
302 * combined stereo camera may never be used at the same time as either of the
303 * two back camera devices (device 0, 1), and typically requires too much
304 * bandwidth to use at the same time as the front camera (device 3).
305 *
306 * Configuration:
307 *
308 * Camera Device 0 - resource_cost = 50
309 * conflicting_devices = { 2 }
310 * Camera Device 1 - resource_cost = 50
311 * conflicting_devices = { 2 }
312 * Camera Device 2 - resource_cost = 100
313 * conflicting_devices = { 0, 1 }
314 * Camera Device 3 - resource_cost = 50
315 * conflicting_devices = null
316 *
317 * Result:
318 *
319 * Based on the conflicting_devices fields, the camera service guarantees that
320 * the following sets of open devices will never be allowed: { 1, 2 }, { 0, 2 }.
321 *
322 * Based on the resource_cost fields, if a high-priority foreground application
323 * is using camera device 0, a background application would be allowed to open
324 * camera device 1 or 3 (but would be forced to disconnect it again if the
325 * foreground application opened another device).
326 *
327 * The highest priority application may still attempt to simultaneously open
328 * devices 0, 2, and 3, but the HAL may fail in open or configure calls for
329 * this combination.
330 *
331 * Ex. 3: Camera Device 0 = Back Camera
332 * Camera Device 1 = Front Camera
333 * Camera Device 2 = Low-power Front Camera that uses the same
334 * sensor as device 1, but only exposes image stream
335 * resolutions that can be used in low-power mode
336 * - Using both front cameras (device 1, 2) at the same time is impossible due
337 * a shared physical sensor. Using the back and "high-power" front camera
338 * (device 1) may be impossible for some stream configurations due to hardware
339 * limitations, but the "low-power" front camera option may always be used as
340 * it has special dedicated hardware.
341 *
342 * Configuration:
343 *
344 * Camera Device 0 - resource_cost = 100
345 * conflicting_devices = null
346 * Camera Device 1 - resource_cost = 100
347 * conflicting_devices = { 2 }
348 * Camera Device 2 - resource_cost = 0
349 * conflicting_devices = { 1 }
350 * Result:
351 *
352 * Based on the conflicting_devices fields, the camera service guarantees that
353 * the following sets of open devices will never be allowed: { 1, 2 }.
354 *
355 * Based on the resource_cost fields, only the highest priority application
356 * may attempt to open both device 0 and 1 at the same time. If a higher-priority
357 * application is not using device 1 or 2, a low-priority background application
358 * may open device 2 (but will be forced to disconnect it if a higher-priority
359 * application subsequently opens device 1 or 2).
Ruben Brunk0388bcd2015-01-16 14:29:21 -0800360 *
361 * Version information (based on camera_module_t.common.module_api_version):
362 *
363 * CAMERA_MODULE_API_VERSION_2_3 or lower:
364 *
365 * Not valid. Can be assumed to be 100. Do not read this field.
366 *
367 * CAMERA_MODULE_API_VERSION_2_4 or higher:
368 *
369 * Always valid.
370 */
371 int resource_cost;
372
373 /**
374 * An array of camera device IDs represented as NULL-terminated strings
375 * indicating other devices that cannot be simultaneously opened while this
376 * camera device is in use.
377 *
378 * This field is intended to be used to indicate that this camera device
379 * is a composite of several other camera devices, or otherwise has
380 * hardware dependencies that prohibit simultaneous usage. If there are no
381 * dependencies, a NULL may be returned in this field to indicate this.
382 *
383 * The camera service will never simultaneously open any of the devices
384 * in this list while this camera device is open.
385 *
Ruben Brunk1fa09022015-03-10 11:53:12 -0700386 * The strings pointed to in this field will not be cleaned up by the camera
387 * service, and must remain while this device is plugged in.
388 *
Ruben Brunk0388bcd2015-01-16 14:29:21 -0800389 * Version information (based on camera_module_t.common.module_api_version):
390 *
391 * CAMERA_MODULE_API_VERSION_2_3 or lower:
392 *
393 * Not valid. Can be assumed to be NULL. Do not read this field.
394 *
395 * CAMERA_MODULE_API_VERSION_2_4 or higher:
396 *
397 * Always valid.
398 */
399 char** conflicting_devices;
400
401 /**
402 * The length of the array given in the conflicting_devices field.
403 *
404 * Version information (based on camera_module_t.common.module_api_version):
405 *
406 * CAMERA_MODULE_API_VERSION_2_3 or lower:
407 *
408 * Not valid. Can be assumed to be 0. Do not read this field.
409 *
410 * CAMERA_MODULE_API_VERSION_2_4 or higher:
411 *
412 * Always valid.
413 */
414 size_t conflicting_devices_length;
415
Alex Ray9acc7402013-02-07 15:44:24 -0800416} camera_info_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800417
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800418/**
419 * camera_device_status_t:
420 *
421 * The current status of the camera device, as provided by the HAL through the
422 * camera_module_callbacks.camera_device_status_change() call.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700423 *
424 * At module load time, the framework will assume all camera devices are in the
425 * CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke
426 * camera_module_callbacks::camera_device_status_change to inform the framework
427 * of any initially NOT_PRESENT devices.
428 *
429 * Allowed transitions:
430 * PRESENT -> NOT_PRESENT
431 * NOT_PRESENT -> ENUMERATING
432 * NOT_PRESENT -> PRESENT
433 * ENUMERATING -> PRESENT
434 * ENUMERATING -> NOT_PRESENT
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800435 */
436typedef enum camera_device_status {
437 /**
438 * The camera device is not currently connected, and opening it will return
Zhijun He94e23b22015-01-12 14:45:33 -0800439 * failure.
440 *
441 * Version information (based on camera_module_t.common.module_api_version):
442 *
443 * CAMERA_MODULE_API_VERSION_2_3 or lower:
444 *
445 * Calls to get_camera_info must still succeed, and provide the same information
446 * it would if the camera were connected.
447 *
448 * CAMERA_MODULE_API_VERSION_2_4:
449 *
450 * The camera device at this status must return -EINVAL for get_camera_info call,
451 * as the device is not connected.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800452 */
453 CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
454
455 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800456 * The camera device is connected, and opening it will succeed.
457 *
458 * CAMERA_MODULE_API_VERSION_2_3 or lower:
459 *
460 * The information returned by get_camera_info cannot change due to this status
461 * change. By default, the framework will assume all devices are in this state.
462 *
463 * CAMERA_MODULE_API_VERSION_2_4:
464 *
465 * The information returned by get_camera_info will become valid after a device's
466 * status changes to this. By default, the framework will assume all devices are in
467 * this state.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800468 */
Igor Murashkin152b50f2013-03-18 13:30:14 -0700469 CAMERA_DEVICE_STATUS_PRESENT = 1,
470
471 /**
472 * The camera device is connected, but it is undergoing an enumeration and
Zhijun He94e23b22015-01-12 14:45:33 -0800473 * so opening the device will return -EBUSY.
474 *
475 * CAMERA_MODULE_API_VERSION_2_3 or lower:
476 *
477 * Calls to get_camera_info must still succeed, as if the camera was in the
478 * PRESENT status.
479 *
480 * CAMERA_MODULE_API_VERSION_2_4:
481 *
482 * The camera device at this status must return -EINVAL for get_camera_info for call,
483 * as the device is not ready.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700484 */
485 CAMERA_DEVICE_STATUS_ENUMERATING = 2,
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800486
487} camera_device_status_t;
488
489/**
Chien-Yu Chen30159172015-01-08 11:06:38 -0800490 * torch_mode_status_t:
491 *
492 * The current status of the torch mode, as provided by the HAL through the
493 * camera_module_callbacks.torch_mode_status_change() call.
494 *
495 * The torch mode status of a camera device is applicable only when the camera
496 * device is present. The framework will not call set_torch_mode() to turn on
497 * torch mode of a camera device if the camera device is not present. At module
498 * load time, the framework will assume torch modes are in the
Chien-Yu Chen85585102015-02-25 14:50:13 -0800499 * TORCH_MODE_STATUS_OFF state if the camera device is present and
Chien-Yu Chen30159172015-01-08 11:06:38 -0800500 * android.flash.info.available is reported as true via get_camera_info() call.
501 *
502 * The behaviors of the camera HAL module that the framework expects in the
503 * following situations when a camera device's status changes:
504 * 1. A previously-disconnected camera device becomes connected.
505 * After camera_module_callbacks::camera_device_status_change() is invoked
506 * to inform the framework that the camera device is present, the framework
507 * will assume the camera device's torch mode is in
Chien-Yu Chen85585102015-02-25 14:50:13 -0800508 * TORCH_MODE_STATUS_OFF state. The camera HAL module does not need
Chien-Yu Chen30159172015-01-08 11:06:38 -0800509 * to invoke camera_module_callbacks::torch_mode_status_change() unless the
510 * flash unit is unavailable to use by set_torch_mode().
511 *
512 * 2. A previously-connected camera becomes disconnected.
513 * After camera_module_callbacks::camera_device_status_change() is invoked
514 * to inform the framework that the camera device is not present, the
515 * framework will not call set_torch_mode() for the disconnected camera
516 * device until its flash unit becomes available again. The camera HAL
517 * module does not need to invoke
518 * camera_module_callbacks::torch_mode_status_change() separately to inform
519 * that the flash unit has become unavailable.
520 *
521 * 3. open() is called to open a camera device.
522 * The camera HAL module must invoke
523 * camera_module_callbacks::torch_mode_status_change() for all flash units
Chien-Yu Chen85585102015-02-25 14:50:13 -0800524 * that have entered TORCH_MODE_STATUS_NOT_AVAILABLE state and can not be
Chien-Yu Chen30159172015-01-08 11:06:38 -0800525 * turned on by calling set_torch_mode() anymore due to this open() call.
526 *
527 * 4. close() is called to close a camera device.
528 * The camera HAL module must invoke
529 * camera_module_callbacks::torch_mode_status_change() for all flash units
Chien-Yu Chen85585102015-02-25 14:50:13 -0800530 * that have entered TORCH_MODE_STATUS_OFF state and can be turned
Chien-Yu Chen30159172015-01-08 11:06:38 -0800531 * on by calling set_torch_mode() again because of enough resources freed
532 * up by this close() call.
533 *
Chien-Yu Chen85585102015-02-25 14:50:13 -0800534 * Note that the framework calling set_torch_mode() successfully must trigger
535 * TORCH_MODE_STATUS_OFF or TORCH_MODE_STATUS_ON callback for the given camera
536 * device. Additionally it must trigger TORCH_MODE_STATUS_OFF callbacks for
537 * other previously-on torch modes if HAL cannot keep multiple torch modes on
538 * simultaneously.
Chien-Yu Chen30159172015-01-08 11:06:38 -0800539 */
540typedef enum torch_mode_status {
Chien-Yu Chen30159172015-01-08 11:06:38 -0800541
542 /**
543 * The flash unit is no longer available and the torch mode can not be
544 * turned on by calling set_torch_mode(). If the torch mode is on, it
545 * will be turned off by HAL before HAL calls torch_mode_status_change().
546 */
Chien-Yu Chen85585102015-02-25 14:50:13 -0800547 TORCH_MODE_STATUS_NOT_AVAILABLE = 0,
Chien-Yu Chen30159172015-01-08 11:06:38 -0800548
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800549 /**
Chien-Yu Chen85585102015-02-25 14:50:13 -0800550 * A torch mode has become off and available to be turned on via
551 * set_torch_mode(). This may happen in the following
552 * cases:
553 * 1. After the resources to turn on the torch mode have become available.
554 * 2. After set_torch_mode() is called to turn off the torch mode.
555 * 3. After the framework turned on the torch mode of some other camera
556 * device and HAL had to turn off the torch modes of any camera devices
557 * that were previously on.
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800558 */
Chien-Yu Chen85585102015-02-25 14:50:13 -0800559 TORCH_MODE_STATUS_AVAILABLE_OFF = 1,
560
561 /**
562 * A torch mode has become on and available to be turned off via
563 * set_torch_mode(). This can happen only after set_torch_mode() is called
564 * to turn on the torch mode.
565 */
566 TORCH_MODE_STATUS_AVAILABLE_ON = 2,
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800567
Chien-Yu Chen30159172015-01-08 11:06:38 -0800568} torch_mode_status_t;
569
570/**
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800571 * Callback functions for the camera HAL module to use to inform the framework
Chien-Yu Chen30159172015-01-08 11:06:38 -0800572 * of changes to the camera subsystem.
573 *
574 * Version information (based on camera_module_t.common.module_api_version):
575 *
576 * Each callback is called only by HAL modules implementing the indicated
577 * version or higher of the HAL module API interface.
578 *
579 * CAMERA_MODULE_API_VERSION_2_1:
580 * camera_device_status_change()
581 *
582 * CAMERA_MODULE_API_VERSION_2_4:
583 * torch_mode_status_change()
584
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800585 */
586typedef struct camera_module_callbacks {
587
588 /**
589 * camera_device_status_change:
590 *
591 * Callback to the framework to indicate that the state of a specific camera
592 * device has changed. At module load time, the framework will assume all
593 * camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
594 * must call this method to inform the framework of any initially
595 * NOT_PRESENT devices.
596 *
Chien-Yu Chen30159172015-01-08 11:06:38 -0800597 * This callback is added for CAMERA_MODULE_API_VERSION_2_1.
598 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800599 * camera_module_callbacks: The instance of camera_module_callbacks_t passed
600 * to the module with set_callbacks.
601 *
602 * camera_id: The ID of the camera device that has a new status.
603 *
604 * new_status: The new status code, one of the camera_device_status_t enums,
605 * or a platform-specific status.
606 *
607 */
608 void (*camera_device_status_change)(const struct camera_module_callbacks*,
609 int camera_id,
610 int new_status);
611
Chien-Yu Chen30159172015-01-08 11:06:38 -0800612 /**
613 * torch_mode_status_change:
614 *
615 * Callback to the framework to indicate that the state of the torch mode
616 * of the flash unit associated with a specific camera device has changed.
617 * At module load time, the framework will assume the torch modes are in
618 * the TORCH_MODE_STATUS_AVAILABLE state if android.flash.info.available
619 * is reported as true via get_camera_info() call.
620 *
621 * This callback is added for CAMERA_MODULE_API_VERSION_2_4.
622 *
623 * camera_module_callbacks: The instance of camera_module_callbacks_t
624 * passed to the module with set_callbacks.
625 *
626 * camera_id: The ID of camera device whose flash unit has a new torch mode
627 * status.
628 *
629 * new_status: The new status code, one of the torch_mode_status_t enums.
630 */
631 void (*torch_mode_status_change)(const struct camera_module_callbacks*,
632 const char* camera_id,
633 int new_status);
634
635
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800636} camera_module_callbacks_t;
637
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800638typedef struct camera_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700639 /**
640 * Common methods of the camera module. This *must* be the first member of
641 * camera_module as users of this structure will cast a hw_module_t to
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700642 * camera_module pointer in contexts where it's known the hw_module_t
643 * references a camera_module.
644 *
645 * The return values for common.methods->open for camera_module are:
646 *
647 * 0: On a successful open of the camera device.
648 *
649 * -ENODEV: The camera device cannot be opened due to an internal
650 * error.
651 *
652 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
653 * and/or the module is invalid.
654 *
655 * -EBUSY: The camera device was already opened for this camera id
656 * (by using this method or open_legacy),
657 * regardless of the device HAL version it was opened as.
658 *
659 * -EUSERS: The maximal number of camera devices that can be
660 * opened concurrently were opened already, either by
661 * this method or the open_legacy method.
662 *
663 * All other return values from common.methods->open will be treated as
664 * -ENODEV.
Stewart Miles84d35492014-05-01 09:03:27 -0700665 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800666 hw_module_t common;
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800667
668 /**
669 * get_number_of_cameras:
670 *
671 * Returns the number of camera devices accessible through the camera
672 * module. The camera devices are numbered 0 through N-1, where N is the
673 * value returned by this call. The name of the camera device for open() is
674 * simply the number converted to a string. That is, "0" for camera ID 0,
675 * "1" for camera ID 1.
676 *
Zhijun He94e23b22015-01-12 14:45:33 -0800677 * Version information (based on camera_module_t.common.module_api_version):
678 *
679 * CAMERA_MODULE_API_VERSION_2_3 or lower:
680 *
681 * The value here must be static, and cannot change after the first call
682 * to this method.
683 *
684 * CAMERA_MODULE_API_VERSION_2_4 or higher:
685 *
686 * The value here must be static, and must count only built-in cameras,
687 * which have CAMERA_FACING_BACK or CAMERA_FACING_FRONT camera facing values
688 * (camera_info.facing). The HAL must not include the external cameras
689 * (camera_info.facing == CAMERA_FACING_EXTERNAL) into the return value
690 * of this call. Frameworks will use camera_device_status_change callback
691 * to manage number of external cameras.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800692 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800693 int (*get_number_of_cameras)(void);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800694
695 /**
696 * get_camera_info:
697 *
698 * Return the static camera information for a given camera device. This
699 * information may not change for a camera device.
700 *
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700701 * Return values:
702 *
703 * 0: On a successful operation
704 *
705 * -ENODEV: The information cannot be provided due to an internal
706 * error.
707 *
708 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
709 * and/or the module is invalid.
Zhijun He94e23b22015-01-12 14:45:33 -0800710 *
711 * Version information (based on camera_module_t.common.module_api_version):
712 *
713 * CAMERA_MODULE_API_VERSION_2_4 or higher:
714 *
715 * When a camera is disconnected, its camera id becomes invalid. Calling this
716 * this method with this invalid camera id will get -EINVAL and NULL camera
717 * static metadata (camera_info.static_camera_characteristics).
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800718 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800719 int (*get_camera_info)(int camera_id, struct camera_info *info);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800720
721 /**
722 * set_callbacks:
723 *
724 * Provide callback function pointers to the HAL module to inform framework
725 * of asynchronous camera module events. The framework will call this
726 * function once after initial camera HAL module load, after the
727 * get_number_of_cameras() method is called for the first time, and before
728 * any other calls to the module.
729 *
730 * Version information (based on camera_module_t.common.module_api_version):
731 *
732 * CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
733 *
734 * Not provided by HAL module. Framework may not call this function.
735 *
736 * CAMERA_MODULE_API_VERSION_2_1:
737 *
738 * Valid to be called by the framework.
739 *
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700740 * Return values:
741 *
742 * 0: On a successful operation
743 *
744 * -ENODEV: The operation cannot be completed due to an internal
745 * error.
746 *
747 * -EINVAL: The input arguments are invalid, i.e. the callbacks are
748 * null
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800749 */
750 int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
751
Alex Ray19b2cea2013-06-13 12:40:52 -0700752 /**
753 * get_vendor_tag_ops:
754 *
755 * Get methods to query for vendor extension metadata tag information. The
756 * HAL should fill in all the vendor tag operation methods, or leave ops
757 * unchanged if no vendor tags are defined.
758 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800759 * The vendor_tag_ops structure used here is defined in:
760 * system/media/camera/include/system/vendor_tags.h
761 *
Alex Ray19b2cea2013-06-13 12:40:52 -0700762 * Version information (based on camera_module_t.common.module_api_version):
763 *
764 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1:
765 * Not provided by HAL module. Framework may not call this function.
766 *
767 * CAMERA_MODULE_API_VERSION_2_2:
768 * Valid to be called by the framework.
769 */
770 void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops);
771
Zhijun Hebcdebf32014-06-06 15:42:17 -0700772 /**
773 * open_legacy:
774 *
775 * Open a specific legacy camera HAL device if multiple device HAL API
776 * versions are supported by this camera HAL module. For example, if the
777 * camera module supports both CAMERA_DEVICE_API_VERSION_1_0 and
778 * CAMERA_DEVICE_API_VERSION_3_2 device API for the same camera id,
779 * framework can call this function to open the camera device as
780 * CAMERA_DEVICE_API_VERSION_1_0 device.
781 *
782 * This is an optional method. A Camera HAL module does not need to support
783 * more than one device HAL version per device, and such modules may return
784 * -ENOSYS for all calls to this method. For all older HAL device API
785 * versions that are not supported, it may return -EOPNOTSUPP. When above
786 * cases occur, The normal open() method (common.methods->open) will be
787 * used by the framework instead.
788 *
789 * Version information (based on camera_module_t.common.module_api_version):
790 *
791 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2:
792 * Not provided by HAL module. Framework will not call this function.
793 *
794 * CAMERA_MODULE_API_VERSION_2_3:
795 * Valid to be called by the framework.
796 *
797 * Return values:
798 *
799 * 0: On a successful open of the camera device.
800 *
801 * -ENOSYS This method is not supported.
802 *
803 * -EOPNOTSUPP: The requested HAL version is not supported by this method.
804 *
805 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
806 * and/or the module is invalid.
807 *
808 * -EBUSY: The camera device was already opened for this camera id
809 * (by using this method or common.methods->open method),
810 * regardless of the device HAL version it was opened as.
811 *
812 * -EUSERS: The maximal number of camera devices that can be
813 * opened concurrently were opened already, either by
814 * this method or common.methods->open method.
815 */
816 int (*open_legacy)(const struct hw_module_t* module, const char* id,
817 uint32_t halVersion, struct hw_device_t** device);
818
Chien-Yu Chen30159172015-01-08 11:06:38 -0800819 /**
820 * set_torch_mode:
821 *
822 * Turn on or off the torch mode of the flash unit associated with a given
Chien-Yu Chen85585102015-02-25 14:50:13 -0800823 * camera ID. If the operation is successful, HAL must notify the framework
824 * torch state by invoking
825 * camera_module_callbacks.torch_mode_status_change() with the new state.
Chien-Yu Chen30159172015-01-08 11:06:38 -0800826 *
827 * The camera device has a higher priority accessing the flash unit. When
828 * there are any resource conflicts, such as open() is called to open a
829 * camera device, HAL module must notify the framework through
830 * camera_module_callbacks.torch_mode_status_change() that the
831 * torch mode has been turned off and the torch mode state has become
Chien-Yu Chen85585102015-02-25 14:50:13 -0800832 * TORCH_MODE_STATUS_NOT_AVAILABLE. When resources to turn on torch mode
Chien-Yu Chen30159172015-01-08 11:06:38 -0800833 * become available again, HAL module must notify the framework through
834 * camera_module_callbacks.torch_mode_status_change() that the torch mode
Chien-Yu Chen85585102015-02-25 14:50:13 -0800835 * state has become TORCH_MODE_STATUS_OFF for set_torch_mode() to be called.
Chien-Yu Chen30159172015-01-08 11:06:38 -0800836 *
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800837 * When the framework calls set_torch_mode() to turn on the torch mode of a
838 * flash unit, if HAL cannot keep multiple torch modes on simultaneously,
839 * HAL should turn off the torch mode that was turned on by
840 * a previous set_torch_mode() call and notify the framework that the torch
841 * mode state of that flash unit has become TORCH_MODE_STATUS_OFF.
842 *
Chien-Yu Chen30159172015-01-08 11:06:38 -0800843 * Version information (based on camera_module_t.common.module_api_version):
844 *
845 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3:
846 * Not provided by HAL module. Framework will not call this function.
847 *
848 * CAMERA_MODULE_API_VERSION_2_4:
849 * Valid to be called by the framework.
850 *
851 * Return values:
852 *
853 * 0: On a successful operation.
854 *
855 * -ENOSYS: The camera device does not support this operation. It is
856 * returned if and only if android.flash.info.available is
857 * false.
858 *
Chien-Yu Chen273def32015-02-11 11:31:12 -0800859 * -EBUSY: The camera device is already in use.
860 *
861 * -EUSERS: The resources needed to turn on the torch mode are not
862 * available, typically because other camera devices are
863 * holding the resources to make using the flash unit not
864 * possible.
Chien-Yu Chen30159172015-01-08 11:06:38 -0800865 *
866 * -EINVAL: camera_id is invalid.
867 *
868 */
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800869 int (*set_torch_mode)(const char* camera_id, bool enabled);
Chien-Yu Chen30159172015-01-08 11:06:38 -0800870
Alex Ray19b2cea2013-06-13 12:40:52 -0700871 /* reserved for future use */
Chien-Yu Chen30159172015-01-08 11:06:38 -0800872 void* reserved[6];
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800873} camera_module_t;
874
875__END_DECLS
876
877#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */