blob: 0a907b95da5a3a30641e9fe7a41f903afab1c456 [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 /**
239 * The total resource "cost" of using this this camera, represented as
240 * an integer value in the range [0, 100] where 100 represents total usage
241 * of the shared resource that is the limiting bottleneck of the camera
242 * subsystem.
243 *
244 * The camera service must be able to simultaneously open and use any
245 * combination of camera devices exposed by the HAL where the sum of
246 * the resource costs of these cameras is <= 100. For determining cost,
247 * each camera device must be assumed to be configured and operating at
248 * the maximally resource-consuming framerate and stream size settings
249 * available in the configuration settings exposed for that device through
250 * the camera metadata.
251 *
252 * Note: The camera service may still attempt to simultaneously open
253 * combinations of camera devices with a total resource cost > 100. This
254 * may succeed or fail. If this succeeds, combinations of configurations
255 * that are not supported should fail during the configure calls. If the
256 * total resource cost is <= 100, configuration should never fail due to
257 * resource constraints.
258 *
259 * Version information (based on camera_module_t.common.module_api_version):
260 *
261 * CAMERA_MODULE_API_VERSION_2_3 or lower:
262 *
263 * Not valid. Can be assumed to be 100. Do not read this field.
264 *
265 * CAMERA_MODULE_API_VERSION_2_4 or higher:
266 *
267 * Always valid.
268 */
269 int resource_cost;
270
271 /**
272 * An array of camera device IDs represented as NULL-terminated strings
273 * indicating other devices that cannot be simultaneously opened while this
274 * camera device is in use.
275 *
276 * This field is intended to be used to indicate that this camera device
277 * is a composite of several other camera devices, or otherwise has
278 * hardware dependencies that prohibit simultaneous usage. If there are no
279 * dependencies, a NULL may be returned in this field to indicate this.
280 *
281 * The camera service will never simultaneously open any of the devices
282 * in this list while this camera device is open.
283 *
284 * Version information (based on camera_module_t.common.module_api_version):
285 *
286 * CAMERA_MODULE_API_VERSION_2_3 or lower:
287 *
288 * Not valid. Can be assumed to be NULL. Do not read this field.
289 *
290 * CAMERA_MODULE_API_VERSION_2_4 or higher:
291 *
292 * Always valid.
293 */
294 char** conflicting_devices;
295
296 /**
297 * The length of the array given in the conflicting_devices field.
298 *
299 * Version information (based on camera_module_t.common.module_api_version):
300 *
301 * CAMERA_MODULE_API_VERSION_2_3 or lower:
302 *
303 * Not valid. Can be assumed to be 0. Do not read this field.
304 *
305 * CAMERA_MODULE_API_VERSION_2_4 or higher:
306 *
307 * Always valid.
308 */
309 size_t conflicting_devices_length;
310
Alex Ray9acc7402013-02-07 15:44:24 -0800311} camera_info_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800312
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800313/**
314 * camera_device_status_t:
315 *
316 * The current status of the camera device, as provided by the HAL through the
317 * camera_module_callbacks.camera_device_status_change() call.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700318 *
319 * At module load time, the framework will assume all camera devices are in the
320 * CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke
321 * camera_module_callbacks::camera_device_status_change to inform the framework
322 * of any initially NOT_PRESENT devices.
323 *
324 * Allowed transitions:
325 * PRESENT -> NOT_PRESENT
326 * NOT_PRESENT -> ENUMERATING
327 * NOT_PRESENT -> PRESENT
328 * ENUMERATING -> PRESENT
329 * ENUMERATING -> NOT_PRESENT
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800330 */
331typedef enum camera_device_status {
332 /**
333 * The camera device is not currently connected, and opening it will return
Zhijun He94e23b22015-01-12 14:45:33 -0800334 * failure.
335 *
336 * Version information (based on camera_module_t.common.module_api_version):
337 *
338 * CAMERA_MODULE_API_VERSION_2_3 or lower:
339 *
340 * Calls to get_camera_info must still succeed, and provide the same information
341 * it would if the camera were connected.
342 *
343 * CAMERA_MODULE_API_VERSION_2_4:
344 *
345 * The camera device at this status must return -EINVAL for get_camera_info call,
346 * as the device is not connected.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800347 */
348 CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
349
350 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800351 * The camera device is connected, and opening it will succeed.
352 *
353 * CAMERA_MODULE_API_VERSION_2_3 or lower:
354 *
355 * The information returned by get_camera_info cannot change due to this status
356 * change. By default, the framework will assume all devices are in this state.
357 *
358 * CAMERA_MODULE_API_VERSION_2_4:
359 *
360 * The information returned by get_camera_info will become valid after a device's
361 * status changes to this. By default, the framework will assume all devices are in
362 * this state.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800363 */
Igor Murashkin152b50f2013-03-18 13:30:14 -0700364 CAMERA_DEVICE_STATUS_PRESENT = 1,
365
366 /**
367 * The camera device is connected, but it is undergoing an enumeration and
Zhijun He94e23b22015-01-12 14:45:33 -0800368 * so opening the device will return -EBUSY.
369 *
370 * CAMERA_MODULE_API_VERSION_2_3 or lower:
371 *
372 * Calls to get_camera_info must still succeed, as if the camera was in the
373 * PRESENT status.
374 *
375 * CAMERA_MODULE_API_VERSION_2_4:
376 *
377 * The camera device at this status must return -EINVAL for get_camera_info for call,
378 * as the device is not ready.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700379 */
380 CAMERA_DEVICE_STATUS_ENUMERATING = 2,
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800381
382} camera_device_status_t;
383
384/**
Chien-Yu Chen30159172015-01-08 11:06:38 -0800385 * torch_mode_status_t:
386 *
387 * The current status of the torch mode, as provided by the HAL through the
388 * camera_module_callbacks.torch_mode_status_change() call.
389 *
390 * The torch mode status of a camera device is applicable only when the camera
391 * device is present. The framework will not call set_torch_mode() to turn on
392 * torch mode of a camera device if the camera device is not present. At module
393 * load time, the framework will assume torch modes are in the
394 * TORCH_MODE_STATUS_AVAILABLE state if the camera device is present and
395 * android.flash.info.available is reported as true via get_camera_info() call.
396 *
397 * The behaviors of the camera HAL module that the framework expects in the
398 * following situations when a camera device's status changes:
399 * 1. A previously-disconnected camera device becomes connected.
400 * After camera_module_callbacks::camera_device_status_change() is invoked
401 * to inform the framework that the camera device is present, the framework
402 * will assume the camera device's torch mode is in
403 * TORCH_MODE_STATUS_AVAILABLE state. The camera HAL module does not need
404 * to invoke camera_module_callbacks::torch_mode_status_change() unless the
405 * flash unit is unavailable to use by set_torch_mode().
406 *
407 * 2. A previously-connected camera becomes disconnected.
408 * After camera_module_callbacks::camera_device_status_change() is invoked
409 * to inform the framework that the camera device is not present, the
410 * framework will not call set_torch_mode() for the disconnected camera
411 * device until its flash unit becomes available again. The camera HAL
412 * module does not need to invoke
413 * camera_module_callbacks::torch_mode_status_change() separately to inform
414 * that the flash unit has become unavailable.
415 *
416 * 3. open() is called to open a camera device.
417 * The camera HAL module must invoke
418 * camera_module_callbacks::torch_mode_status_change() for all flash units
419 * that have entered TORCH_MODE_STATUS_RESOURCE_BUSY state and can not be
420 * turned on by calling set_torch_mode() anymore due to this open() call.
421 *
422 * 4. close() is called to close a camera device.
423 * The camera HAL module must invoke
424 * camera_module_callbacks::torch_mode_status_change() for all flash units
425 * that have entered TORCH_MODE_STATUS_AVAILABLE state and can be turned
426 * on by calling set_torch_mode() again because of enough resources freed
427 * up by this close() call.
428 *
429 * Note that the framework calling set_torch_mode() should not trigger any
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800430 * callbacks except when HAL cannot keep multiple torch modes on
431 * simultaneously. In that case, HAL must notify the framework that any
432 * previously-on torch mode states have become TORCH_MODE_STATUS_OFF.
433 *
Chien-Yu Chen30159172015-01-08 11:06:38 -0800434 */
435typedef enum torch_mode_status {
436 /**
437 * The flash unit is available and the torch mode can be turned on by
438 * calling set_torch_mode(). By default, the framework will assume all
439 * flash units of all present camera devices are in this state if
440 * android.flash.info.available is reported as true via get_camera_info()
441 * call.
442 */
443 TORCH_MODE_STATUS_AVAILABLE = 0,
444
445 /**
446 * The flash unit is no longer available and the torch mode can not be
447 * turned on by calling set_torch_mode(). If the torch mode is on, it
448 * will be turned off by HAL before HAL calls torch_mode_status_change().
449 */
450 TORCH_MODE_STATUS_RESOURCE_BUSY = 1,
451
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800452 /**
453 * The previously-on torch mode has been turned off by HAL but the flash
454 * unit is still available for set_torch_mode(). This may happen after the
455 * framework turned on the torch mode of some other camera device and HAL
456 * had to turn off the torch modes of any camera devices that were
457 * previously on.
458 */
459 TORCH_MODE_STATUS_OFF = 2,
460
Chien-Yu Chen30159172015-01-08 11:06:38 -0800461} torch_mode_status_t;
462
463/**
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800464 * Callback functions for the camera HAL module to use to inform the framework
Chien-Yu Chen30159172015-01-08 11:06:38 -0800465 * of changes to the camera subsystem.
466 *
467 * Version information (based on camera_module_t.common.module_api_version):
468 *
469 * Each callback is called only by HAL modules implementing the indicated
470 * version or higher of the HAL module API interface.
471 *
472 * CAMERA_MODULE_API_VERSION_2_1:
473 * camera_device_status_change()
474 *
475 * CAMERA_MODULE_API_VERSION_2_4:
476 * torch_mode_status_change()
477
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800478 */
479typedef struct camera_module_callbacks {
480
481 /**
482 * camera_device_status_change:
483 *
484 * Callback to the framework to indicate that the state of a specific camera
485 * device has changed. At module load time, the framework will assume all
486 * camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
487 * must call this method to inform the framework of any initially
488 * NOT_PRESENT devices.
489 *
Chien-Yu Chen30159172015-01-08 11:06:38 -0800490 * This callback is added for CAMERA_MODULE_API_VERSION_2_1.
491 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800492 * camera_module_callbacks: The instance of camera_module_callbacks_t passed
493 * to the module with set_callbacks.
494 *
495 * camera_id: The ID of the camera device that has a new status.
496 *
497 * new_status: The new status code, one of the camera_device_status_t enums,
498 * or a platform-specific status.
499 *
500 */
501 void (*camera_device_status_change)(const struct camera_module_callbacks*,
502 int camera_id,
503 int new_status);
504
Chien-Yu Chen30159172015-01-08 11:06:38 -0800505 /**
506 * torch_mode_status_change:
507 *
508 * Callback to the framework to indicate that the state of the torch mode
509 * of the flash unit associated with a specific camera device has changed.
510 * At module load time, the framework will assume the torch modes are in
511 * the TORCH_MODE_STATUS_AVAILABLE state if android.flash.info.available
512 * is reported as true via get_camera_info() call.
513 *
514 * This callback is added for CAMERA_MODULE_API_VERSION_2_4.
515 *
516 * camera_module_callbacks: The instance of camera_module_callbacks_t
517 * passed to the module with set_callbacks.
518 *
519 * camera_id: The ID of camera device whose flash unit has a new torch mode
520 * status.
521 *
522 * new_status: The new status code, one of the torch_mode_status_t enums.
523 */
524 void (*torch_mode_status_change)(const struct camera_module_callbacks*,
525 const char* camera_id,
526 int new_status);
527
528
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800529} camera_module_callbacks_t;
530
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800531typedef struct camera_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700532 /**
533 * Common methods of the camera module. This *must* be the first member of
534 * camera_module as users of this structure will cast a hw_module_t to
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700535 * camera_module pointer in contexts where it's known the hw_module_t
536 * references a camera_module.
537 *
538 * The return values for common.methods->open for camera_module are:
539 *
540 * 0: On a successful open of the camera device.
541 *
542 * -ENODEV: The camera device cannot be opened due to an internal
543 * error.
544 *
545 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
546 * and/or the module is invalid.
547 *
548 * -EBUSY: The camera device was already opened for this camera id
549 * (by using this method or open_legacy),
550 * regardless of the device HAL version it was opened as.
551 *
552 * -EUSERS: The maximal number of camera devices that can be
553 * opened concurrently were opened already, either by
554 * this method or the open_legacy method.
555 *
556 * All other return values from common.methods->open will be treated as
557 * -ENODEV.
Stewart Miles84d35492014-05-01 09:03:27 -0700558 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800559 hw_module_t common;
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800560
561 /**
562 * get_number_of_cameras:
563 *
564 * Returns the number of camera devices accessible through the camera
565 * module. The camera devices are numbered 0 through N-1, where N is the
566 * value returned by this call. The name of the camera device for open() is
567 * simply the number converted to a string. That is, "0" for camera ID 0,
568 * "1" for camera ID 1.
569 *
Zhijun He94e23b22015-01-12 14:45:33 -0800570 * Version information (based on camera_module_t.common.module_api_version):
571 *
572 * CAMERA_MODULE_API_VERSION_2_3 or lower:
573 *
574 * The value here must be static, and cannot change after the first call
575 * to this method.
576 *
577 * CAMERA_MODULE_API_VERSION_2_4 or higher:
578 *
579 * The value here must be static, and must count only built-in cameras,
580 * which have CAMERA_FACING_BACK or CAMERA_FACING_FRONT camera facing values
581 * (camera_info.facing). The HAL must not include the external cameras
582 * (camera_info.facing == CAMERA_FACING_EXTERNAL) into the return value
583 * of this call. Frameworks will use camera_device_status_change callback
584 * to manage number of external cameras.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800585 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800586 int (*get_number_of_cameras)(void);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800587
588 /**
589 * get_camera_info:
590 *
591 * Return the static camera information for a given camera device. This
592 * information may not change for a camera device.
593 *
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700594 * Return values:
595 *
596 * 0: On a successful operation
597 *
598 * -ENODEV: The information cannot be provided due to an internal
599 * error.
600 *
601 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
602 * and/or the module is invalid.
Zhijun He94e23b22015-01-12 14:45:33 -0800603 *
604 * Version information (based on camera_module_t.common.module_api_version):
605 *
606 * CAMERA_MODULE_API_VERSION_2_4 or higher:
607 *
608 * When a camera is disconnected, its camera id becomes invalid. Calling this
609 * this method with this invalid camera id will get -EINVAL and NULL camera
610 * static metadata (camera_info.static_camera_characteristics).
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800611 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800612 int (*get_camera_info)(int camera_id, struct camera_info *info);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800613
614 /**
615 * set_callbacks:
616 *
617 * Provide callback function pointers to the HAL module to inform framework
618 * of asynchronous camera module events. The framework will call this
619 * function once after initial camera HAL module load, after the
620 * get_number_of_cameras() method is called for the first time, and before
621 * any other calls to the module.
622 *
623 * Version information (based on camera_module_t.common.module_api_version):
624 *
625 * CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
626 *
627 * Not provided by HAL module. Framework may not call this function.
628 *
629 * CAMERA_MODULE_API_VERSION_2_1:
630 *
631 * Valid to be called by the framework.
632 *
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700633 * Return values:
634 *
635 * 0: On a successful operation
636 *
637 * -ENODEV: The operation cannot be completed due to an internal
638 * error.
639 *
640 * -EINVAL: The input arguments are invalid, i.e. the callbacks are
641 * null
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800642 */
643 int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
644
Alex Ray19b2cea2013-06-13 12:40:52 -0700645 /**
646 * get_vendor_tag_ops:
647 *
648 * Get methods to query for vendor extension metadata tag information. The
649 * HAL should fill in all the vendor tag operation methods, or leave ops
650 * unchanged if no vendor tags are defined.
651 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800652 * The vendor_tag_ops structure used here is defined in:
653 * system/media/camera/include/system/vendor_tags.h
654 *
Alex Ray19b2cea2013-06-13 12:40:52 -0700655 * Version information (based on camera_module_t.common.module_api_version):
656 *
657 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1:
658 * Not provided by HAL module. Framework may not call this function.
659 *
660 * CAMERA_MODULE_API_VERSION_2_2:
661 * Valid to be called by the framework.
662 */
663 void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops);
664
Zhijun Hebcdebf32014-06-06 15:42:17 -0700665 /**
666 * open_legacy:
667 *
668 * Open a specific legacy camera HAL device if multiple device HAL API
669 * versions are supported by this camera HAL module. For example, if the
670 * camera module supports both CAMERA_DEVICE_API_VERSION_1_0 and
671 * CAMERA_DEVICE_API_VERSION_3_2 device API for the same camera id,
672 * framework can call this function to open the camera device as
673 * CAMERA_DEVICE_API_VERSION_1_0 device.
674 *
675 * This is an optional method. A Camera HAL module does not need to support
676 * more than one device HAL version per device, and such modules may return
677 * -ENOSYS for all calls to this method. For all older HAL device API
678 * versions that are not supported, it may return -EOPNOTSUPP. When above
679 * cases occur, The normal open() method (common.methods->open) will be
680 * used by the framework instead.
681 *
682 * Version information (based on camera_module_t.common.module_api_version):
683 *
684 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2:
685 * Not provided by HAL module. Framework will not call this function.
686 *
687 * CAMERA_MODULE_API_VERSION_2_3:
688 * Valid to be called by the framework.
689 *
690 * Return values:
691 *
692 * 0: On a successful open of the camera device.
693 *
694 * -ENOSYS This method is not supported.
695 *
696 * -EOPNOTSUPP: The requested HAL version is not supported by this method.
697 *
698 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
699 * and/or the module is invalid.
700 *
701 * -EBUSY: The camera device was already opened for this camera id
702 * (by using this method or common.methods->open method),
703 * regardless of the device HAL version it was opened as.
704 *
705 * -EUSERS: The maximal number of camera devices that can be
706 * opened concurrently were opened already, either by
707 * this method or common.methods->open method.
708 */
709 int (*open_legacy)(const struct hw_module_t* module, const char* id,
710 uint32_t halVersion, struct hw_device_t** device);
711
Chien-Yu Chen30159172015-01-08 11:06:38 -0800712 /**
713 * set_torch_mode:
714 *
715 * Turn on or off the torch mode of the flash unit associated with a given
716 * camera ID. This function is blocking until the operation completes or
717 * fails.
718 *
719 * The camera device has a higher priority accessing the flash unit. When
720 * there are any resource conflicts, such as open() is called to open a
721 * camera device, HAL module must notify the framework through
722 * camera_module_callbacks.torch_mode_status_change() that the
723 * torch mode has been turned off and the torch mode state has become
724 * TORCH_MODE_STATUS_RESOURCE_BUSY. When resources to turn on torch mode
725 * become available again, HAL module must notify the framework through
726 * camera_module_callbacks.torch_mode_status_change() that the torch mode
727 * state has become available for set_torch_mode() to be called.
728 *
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800729 * When the framework calls set_torch_mode() to turn on the torch mode of a
730 * flash unit, if HAL cannot keep multiple torch modes on simultaneously,
731 * HAL should turn off the torch mode that was turned on by
732 * a previous set_torch_mode() call and notify the framework that the torch
733 * mode state of that flash unit has become TORCH_MODE_STATUS_OFF.
734 *
Chien-Yu Chen30159172015-01-08 11:06:38 -0800735 * Version information (based on camera_module_t.common.module_api_version):
736 *
737 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3:
738 * Not provided by HAL module. Framework will not call this function.
739 *
740 * CAMERA_MODULE_API_VERSION_2_4:
741 * Valid to be called by the framework.
742 *
743 * Return values:
744 *
745 * 0: On a successful operation.
746 *
747 * -ENOSYS: The camera device does not support this operation. It is
748 * returned if and only if android.flash.info.available is
749 * false.
750 *
Chien-Yu Chen273def32015-02-11 11:31:12 -0800751 * -EBUSY: The camera device is already in use.
752 *
753 * -EUSERS: The resources needed to turn on the torch mode are not
754 * available, typically because other camera devices are
755 * holding the resources to make using the flash unit not
756 * possible.
Chien-Yu Chen30159172015-01-08 11:06:38 -0800757 *
758 * -EINVAL: camera_id is invalid.
759 *
760 */
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800761 int (*set_torch_mode)(const char* camera_id, bool enabled);
Chien-Yu Chen30159172015-01-08 11:06:38 -0800762
Alex Ray19b2cea2013-06-13 12:40:52 -0700763 /* reserved for future use */
Chien-Yu Chen30159172015-01-08 11:06:38 -0800764 void* reserved[6];
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800765} camera_module_t;
766
767__END_DECLS
768
769#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */