blob: 971ed8083d85b915b066d7e8a32c3f94e8df74f0 [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)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700145
Eino-Ville Talvalab5459832014-09-09 16:42:27 -0700146// Device version 3.2 is current, older HAL camera device versions are not
147// recommended for new devices.
148#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_3_2
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800149
150/**
James Dongd0ca70d2012-03-26 16:22:35 -0700151 * Defined in /system/media/camera/include/system/camera_metadata.h
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800152 */
153typedef struct camera_metadata camera_metadata_t;
154
Alex Ray9acc7402013-02-07 15:44:24 -0800155typedef struct camera_info {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800156 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800157 * The direction that the camera faces to. See system/core/include/system/camera.h
158 * for camera facing definitions.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800159 *
Zhijun He94e23b22015-01-12 14:45:33 -0800160 * Version information (based on camera_module_t.common.module_api_version):
161 *
162 * CAMERA_MODULE_API_VERSION_2_3 or lower:
163 *
164 * It should be CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
165 *
166 * CAMERA_MODULE_API_VERSION_2_4 or higher:
167 *
168 * It should be CAMERA_FACING_BACK, CAMERA_FACING_FRONT or
169 * CAMERA_FACING_EXTERNAL.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800170 */
171 int facing;
172
173 /**
174 * The orientation of the camera image. The value is the angle that the
175 * camera image needs to be rotated clockwise so it shows correctly on the
176 * display in its natural orientation. It should be 0, 90, 180, or 270.
177 *
178 * For example, suppose a device has a naturally tall screen. The
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800179 * back-facing camera sensor is mounted in landscape. You are looking at the
180 * screen. If the top side of the camera sensor is aligned with the right
181 * edge of the screen in natural orientation, the value should be 90. If the
182 * top side of a front-facing camera sensor is aligned with the right of the
183 * screen, the value should be 270.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800184 *
Zhijun He94e23b22015-01-12 14:45:33 -0800185 * Version information (based on camera_module_t.common.module_api_version):
186 *
187 * CAMERA_MODULE_API_VERSION_2_3 or lower:
188 *
189 * Valid in all camera_module versions.
190 *
191 * CAMERA_MODULE_API_VERSION_2_4 or higher:
192 *
193 * Valid if camera facing is CAMERA_FACING_BACK or CAMERA_FACING_FRONT,
194 * not valid if camera facing is CAMERA_FACING_EXTERNAL.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800195 */
196 int orientation;
197
198 /**
199 * The value of camera_device_t.common.version.
200 *
201 * Version information (based on camera_module_t.common.module_api_version):
202 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700203 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800204 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700205 * Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800206 * not read this field.
207 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800208 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800209 *
210 * Always valid
211 *
212 */
213 uint32_t device_version;
214
215 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800216 * The camera's fixed characteristics, which include all static camera metadata
217 * specified in system/media/camera/docs/docs.html. This should be a sorted metadata
218 * buffer, and may not be modified or freed by the caller. The pointer should remain
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800219 * valid for the lifetime of the camera module, and values in it may not
220 * change after it is returned by get_camera_info().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800221 *
222 * Version information (based on camera_module_t.common.module_api_version):
223 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700224 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800225 *
226 * Not valid. Extra characteristics are not available. Do not read this
227 * field.
228 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800229 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800230 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700231 * Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
232 * otherwise.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800233 *
234 */
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700235 const camera_metadata_t *static_camera_characteristics;
Ruben Brunk0388bcd2015-01-16 14:29:21 -0800236
237 /**
238 * The total resource "cost" of using this this camera, represented as
239 * an integer value in the range [0, 100] where 100 represents total usage
240 * of the shared resource that is the limiting bottleneck of the camera
241 * subsystem.
242 *
243 * The camera service must be able to simultaneously open and use any
244 * combination of camera devices exposed by the HAL where the sum of
245 * the resource costs of these cameras is <= 100. For determining cost,
246 * each camera device must be assumed to be configured and operating at
247 * the maximally resource-consuming framerate and stream size settings
248 * available in the configuration settings exposed for that device through
249 * the camera metadata.
250 *
251 * Note: The camera service may still attempt to simultaneously open
252 * combinations of camera devices with a total resource cost > 100. This
253 * may succeed or fail. If this succeeds, combinations of configurations
254 * that are not supported should fail during the configure calls. If the
255 * total resource cost is <= 100, configuration should never fail due to
256 * resource constraints.
257 *
258 * Version information (based on camera_module_t.common.module_api_version):
259 *
260 * CAMERA_MODULE_API_VERSION_2_3 or lower:
261 *
262 * Not valid. Can be assumed to be 100. Do not read this field.
263 *
264 * CAMERA_MODULE_API_VERSION_2_4 or higher:
265 *
266 * Always valid.
267 */
268 int resource_cost;
269
270 /**
271 * An array of camera device IDs represented as NULL-terminated strings
272 * indicating other devices that cannot be simultaneously opened while this
273 * camera device is in use.
274 *
275 * This field is intended to be used to indicate that this camera device
276 * is a composite of several other camera devices, or otherwise has
277 * hardware dependencies that prohibit simultaneous usage. If there are no
278 * dependencies, a NULL may be returned in this field to indicate this.
279 *
280 * The camera service will never simultaneously open any of the devices
281 * in this list while this camera device is open.
282 *
283 * Version information (based on camera_module_t.common.module_api_version):
284 *
285 * CAMERA_MODULE_API_VERSION_2_3 or lower:
286 *
287 * Not valid. Can be assumed to be NULL. Do not read this field.
288 *
289 * CAMERA_MODULE_API_VERSION_2_4 or higher:
290 *
291 * Always valid.
292 */
293 char** conflicting_devices;
294
295 /**
296 * The length of the array given in the conflicting_devices field.
297 *
298 * Version information (based on camera_module_t.common.module_api_version):
299 *
300 * CAMERA_MODULE_API_VERSION_2_3 or lower:
301 *
302 * Not valid. Can be assumed to be 0. Do not read this field.
303 *
304 * CAMERA_MODULE_API_VERSION_2_4 or higher:
305 *
306 * Always valid.
307 */
308 size_t conflicting_devices_length;
309
Alex Ray9acc7402013-02-07 15:44:24 -0800310} camera_info_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800311
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800312/**
313 * camera_device_status_t:
314 *
315 * The current status of the camera device, as provided by the HAL through the
316 * camera_module_callbacks.camera_device_status_change() call.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700317 *
318 * At module load time, the framework will assume all camera devices are in the
319 * CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke
320 * camera_module_callbacks::camera_device_status_change to inform the framework
321 * of any initially NOT_PRESENT devices.
322 *
323 * Allowed transitions:
324 * PRESENT -> NOT_PRESENT
325 * NOT_PRESENT -> ENUMERATING
326 * NOT_PRESENT -> PRESENT
327 * ENUMERATING -> PRESENT
328 * ENUMERATING -> NOT_PRESENT
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800329 */
330typedef enum camera_device_status {
331 /**
332 * The camera device is not currently connected, and opening it will return
Zhijun He94e23b22015-01-12 14:45:33 -0800333 * failure.
334 *
335 * Version information (based on camera_module_t.common.module_api_version):
336 *
337 * CAMERA_MODULE_API_VERSION_2_3 or lower:
338 *
339 * Calls to get_camera_info must still succeed, and provide the same information
340 * it would if the camera were connected.
341 *
342 * CAMERA_MODULE_API_VERSION_2_4:
343 *
344 * The camera device at this status must return -EINVAL for get_camera_info call,
345 * as the device is not connected.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800346 */
347 CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
348
349 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800350 * The camera device is connected, and opening it will succeed.
351 *
352 * CAMERA_MODULE_API_VERSION_2_3 or lower:
353 *
354 * The information returned by get_camera_info cannot change due to this status
355 * change. By default, the framework will assume all devices are in this state.
356 *
357 * CAMERA_MODULE_API_VERSION_2_4:
358 *
359 * The information returned by get_camera_info will become valid after a device's
360 * status changes to this. By default, the framework will assume all devices are in
361 * this state.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800362 */
Igor Murashkin152b50f2013-03-18 13:30:14 -0700363 CAMERA_DEVICE_STATUS_PRESENT = 1,
364
365 /**
366 * The camera device is connected, but it is undergoing an enumeration and
Zhijun He94e23b22015-01-12 14:45:33 -0800367 * so opening the device will return -EBUSY.
368 *
369 * CAMERA_MODULE_API_VERSION_2_3 or lower:
370 *
371 * Calls to get_camera_info must still succeed, as if the camera was in the
372 * PRESENT status.
373 *
374 * CAMERA_MODULE_API_VERSION_2_4:
375 *
376 * The camera device at this status must return -EINVAL for get_camera_info for call,
377 * as the device is not ready.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700378 */
379 CAMERA_DEVICE_STATUS_ENUMERATING = 2,
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800380
381} camera_device_status_t;
382
383/**
Chien-Yu Chen30159172015-01-08 11:06:38 -0800384 * torch_mode_status_t:
385 *
386 * The current status of the torch mode, as provided by the HAL through the
387 * camera_module_callbacks.torch_mode_status_change() call.
388 *
389 * The torch mode status of a camera device is applicable only when the camera
390 * device is present. The framework will not call set_torch_mode() to turn on
391 * torch mode of a camera device if the camera device is not present. At module
392 * load time, the framework will assume torch modes are in the
393 * TORCH_MODE_STATUS_AVAILABLE state if the camera device is present and
394 * android.flash.info.available is reported as true via get_camera_info() call.
395 *
396 * The behaviors of the camera HAL module that the framework expects in the
397 * following situations when a camera device's status changes:
398 * 1. A previously-disconnected camera device becomes connected.
399 * After camera_module_callbacks::camera_device_status_change() is invoked
400 * to inform the framework that the camera device is present, the framework
401 * will assume the camera device's torch mode is in
402 * TORCH_MODE_STATUS_AVAILABLE state. The camera HAL module does not need
403 * to invoke camera_module_callbacks::torch_mode_status_change() unless the
404 * flash unit is unavailable to use by set_torch_mode().
405 *
406 * 2. A previously-connected camera becomes disconnected.
407 * After camera_module_callbacks::camera_device_status_change() is invoked
408 * to inform the framework that the camera device is not present, the
409 * framework will not call set_torch_mode() for the disconnected camera
410 * device until its flash unit becomes available again. The camera HAL
411 * module does not need to invoke
412 * camera_module_callbacks::torch_mode_status_change() separately to inform
413 * that the flash unit has become unavailable.
414 *
415 * 3. open() is called to open a camera device.
416 * The camera HAL module must invoke
417 * camera_module_callbacks::torch_mode_status_change() for all flash units
418 * that have entered TORCH_MODE_STATUS_RESOURCE_BUSY state and can not be
419 * turned on by calling set_torch_mode() anymore due to this open() call.
420 *
421 * 4. close() is called to close a camera device.
422 * The camera HAL module must invoke
423 * camera_module_callbacks::torch_mode_status_change() for all flash units
424 * that have entered TORCH_MODE_STATUS_AVAILABLE state and can be turned
425 * on by calling set_torch_mode() again because of enough resources freed
426 * up by this close() call.
427 *
428 * Note that the framework calling set_torch_mode() should not trigger any
429 * callbacks.
430 */
431typedef enum torch_mode_status {
432 /**
433 * The flash unit is available and the torch mode can be turned on by
434 * calling set_torch_mode(). By default, the framework will assume all
435 * flash units of all present camera devices are in this state if
436 * android.flash.info.available is reported as true via get_camera_info()
437 * call.
438 */
439 TORCH_MODE_STATUS_AVAILABLE = 0,
440
441 /**
442 * The flash unit is no longer available and the torch mode can not be
443 * turned on by calling set_torch_mode(). If the torch mode is on, it
444 * will be turned off by HAL before HAL calls torch_mode_status_change().
445 */
446 TORCH_MODE_STATUS_RESOURCE_BUSY = 1,
447
448} torch_mode_status_t;
449
450/**
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800451 * Callback functions for the camera HAL module to use to inform the framework
Chien-Yu Chen30159172015-01-08 11:06:38 -0800452 * of changes to the camera subsystem.
453 *
454 * Version information (based on camera_module_t.common.module_api_version):
455 *
456 * Each callback is called only by HAL modules implementing the indicated
457 * version or higher of the HAL module API interface.
458 *
459 * CAMERA_MODULE_API_VERSION_2_1:
460 * camera_device_status_change()
461 *
462 * CAMERA_MODULE_API_VERSION_2_4:
463 * torch_mode_status_change()
464
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800465 */
466typedef struct camera_module_callbacks {
467
468 /**
469 * camera_device_status_change:
470 *
471 * Callback to the framework to indicate that the state of a specific camera
472 * device has changed. At module load time, the framework will assume all
473 * camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
474 * must call this method to inform the framework of any initially
475 * NOT_PRESENT devices.
476 *
Chien-Yu Chen30159172015-01-08 11:06:38 -0800477 * This callback is added for CAMERA_MODULE_API_VERSION_2_1.
478 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800479 * camera_module_callbacks: The instance of camera_module_callbacks_t passed
480 * to the module with set_callbacks.
481 *
482 * camera_id: The ID of the camera device that has a new status.
483 *
484 * new_status: The new status code, one of the camera_device_status_t enums,
485 * or a platform-specific status.
486 *
487 */
488 void (*camera_device_status_change)(const struct camera_module_callbacks*,
489 int camera_id,
490 int new_status);
491
Chien-Yu Chen30159172015-01-08 11:06:38 -0800492 /**
493 * torch_mode_status_change:
494 *
495 * Callback to the framework to indicate that the state of the torch mode
496 * of the flash unit associated with a specific camera device has changed.
497 * At module load time, the framework will assume the torch modes are in
498 * the TORCH_MODE_STATUS_AVAILABLE state if android.flash.info.available
499 * is reported as true via get_camera_info() call.
500 *
501 * This callback is added for CAMERA_MODULE_API_VERSION_2_4.
502 *
503 * camera_module_callbacks: The instance of camera_module_callbacks_t
504 * passed to the module with set_callbacks.
505 *
506 * camera_id: The ID of camera device whose flash unit has a new torch mode
507 * status.
508 *
509 * new_status: The new status code, one of the torch_mode_status_t enums.
510 */
511 void (*torch_mode_status_change)(const struct camera_module_callbacks*,
512 const char* camera_id,
513 int new_status);
514
515
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800516} camera_module_callbacks_t;
517
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800518typedef struct camera_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700519 /**
520 * Common methods of the camera module. This *must* be the first member of
521 * camera_module as users of this structure will cast a hw_module_t to
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700522 * camera_module pointer in contexts where it's known the hw_module_t
523 * references a camera_module.
524 *
525 * The return values for common.methods->open for camera_module are:
526 *
527 * 0: On a successful open of the camera device.
528 *
529 * -ENODEV: The camera device cannot be opened due to an internal
530 * error.
531 *
532 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
533 * and/or the module is invalid.
534 *
535 * -EBUSY: The camera device was already opened for this camera id
536 * (by using this method or open_legacy),
537 * regardless of the device HAL version it was opened as.
538 *
539 * -EUSERS: The maximal number of camera devices that can be
540 * opened concurrently were opened already, either by
541 * this method or the open_legacy method.
542 *
543 * All other return values from common.methods->open will be treated as
544 * -ENODEV.
Stewart Miles84d35492014-05-01 09:03:27 -0700545 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800546 hw_module_t common;
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800547
548 /**
549 * get_number_of_cameras:
550 *
551 * Returns the number of camera devices accessible through the camera
552 * module. The camera devices are numbered 0 through N-1, where N is the
553 * value returned by this call. The name of the camera device for open() is
554 * simply the number converted to a string. That is, "0" for camera ID 0,
555 * "1" for camera ID 1.
556 *
Zhijun He94e23b22015-01-12 14:45:33 -0800557 * Version information (based on camera_module_t.common.module_api_version):
558 *
559 * CAMERA_MODULE_API_VERSION_2_3 or lower:
560 *
561 * The value here must be static, and cannot change after the first call
562 * to this method.
563 *
564 * CAMERA_MODULE_API_VERSION_2_4 or higher:
565 *
566 * The value here must be static, and must count only built-in cameras,
567 * which have CAMERA_FACING_BACK or CAMERA_FACING_FRONT camera facing values
568 * (camera_info.facing). The HAL must not include the external cameras
569 * (camera_info.facing == CAMERA_FACING_EXTERNAL) into the return value
570 * of this call. Frameworks will use camera_device_status_change callback
571 * to manage number of external cameras.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800572 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800573 int (*get_number_of_cameras)(void);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800574
575 /**
576 * get_camera_info:
577 *
578 * Return the static camera information for a given camera device. This
579 * information may not change for a camera device.
580 *
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700581 * Return values:
582 *
583 * 0: On a successful operation
584 *
585 * -ENODEV: The information cannot be provided due to an internal
586 * error.
587 *
588 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
589 * and/or the module is invalid.
Zhijun He94e23b22015-01-12 14:45:33 -0800590 *
591 * Version information (based on camera_module_t.common.module_api_version):
592 *
593 * CAMERA_MODULE_API_VERSION_2_4 or higher:
594 *
595 * When a camera is disconnected, its camera id becomes invalid. Calling this
596 * this method with this invalid camera id will get -EINVAL and NULL camera
597 * static metadata (camera_info.static_camera_characteristics).
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800598 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800599 int (*get_camera_info)(int camera_id, struct camera_info *info);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800600
601 /**
602 * set_callbacks:
603 *
604 * Provide callback function pointers to the HAL module to inform framework
605 * of asynchronous camera module events. The framework will call this
606 * function once after initial camera HAL module load, after the
607 * get_number_of_cameras() method is called for the first time, and before
608 * any other calls to the module.
609 *
610 * Version information (based on camera_module_t.common.module_api_version):
611 *
612 * CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
613 *
614 * Not provided by HAL module. Framework may not call this function.
615 *
616 * CAMERA_MODULE_API_VERSION_2_1:
617 *
618 * Valid to be called by the framework.
619 *
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700620 * Return values:
621 *
622 * 0: On a successful operation
623 *
624 * -ENODEV: The operation cannot be completed due to an internal
625 * error.
626 *
627 * -EINVAL: The input arguments are invalid, i.e. the callbacks are
628 * null
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800629 */
630 int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
631
Alex Ray19b2cea2013-06-13 12:40:52 -0700632 /**
633 * get_vendor_tag_ops:
634 *
635 * Get methods to query for vendor extension metadata tag information. The
636 * HAL should fill in all the vendor tag operation methods, or leave ops
637 * unchanged if no vendor tags are defined.
638 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800639 * The vendor_tag_ops structure used here is defined in:
640 * system/media/camera/include/system/vendor_tags.h
641 *
Alex Ray19b2cea2013-06-13 12:40:52 -0700642 * Version information (based on camera_module_t.common.module_api_version):
643 *
644 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1:
645 * Not provided by HAL module. Framework may not call this function.
646 *
647 * CAMERA_MODULE_API_VERSION_2_2:
648 * Valid to be called by the framework.
649 */
650 void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops);
651
Zhijun Hebcdebf32014-06-06 15:42:17 -0700652 /**
653 * open_legacy:
654 *
655 * Open a specific legacy camera HAL device if multiple device HAL API
656 * versions are supported by this camera HAL module. For example, if the
657 * camera module supports both CAMERA_DEVICE_API_VERSION_1_0 and
658 * CAMERA_DEVICE_API_VERSION_3_2 device API for the same camera id,
659 * framework can call this function to open the camera device as
660 * CAMERA_DEVICE_API_VERSION_1_0 device.
661 *
662 * This is an optional method. A Camera HAL module does not need to support
663 * more than one device HAL version per device, and such modules may return
664 * -ENOSYS for all calls to this method. For all older HAL device API
665 * versions that are not supported, it may return -EOPNOTSUPP. When above
666 * cases occur, The normal open() method (common.methods->open) will be
667 * used by the framework instead.
668 *
669 * Version information (based on camera_module_t.common.module_api_version):
670 *
671 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2:
672 * Not provided by HAL module. Framework will not call this function.
673 *
674 * CAMERA_MODULE_API_VERSION_2_3:
675 * Valid to be called by the framework.
676 *
677 * Return values:
678 *
679 * 0: On a successful open of the camera device.
680 *
681 * -ENOSYS This method is not supported.
682 *
683 * -EOPNOTSUPP: The requested HAL version is not supported by this method.
684 *
685 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
686 * and/or the module is invalid.
687 *
688 * -EBUSY: The camera device was already opened for this camera id
689 * (by using this method or common.methods->open method),
690 * regardless of the device HAL version it was opened as.
691 *
692 * -EUSERS: The maximal number of camera devices that can be
693 * opened concurrently were opened already, either by
694 * this method or common.methods->open method.
695 */
696 int (*open_legacy)(const struct hw_module_t* module, const char* id,
697 uint32_t halVersion, struct hw_device_t** device);
698
Chien-Yu Chen30159172015-01-08 11:06:38 -0800699 /**
700 * set_torch_mode:
701 *
702 * Turn on or off the torch mode of the flash unit associated with a given
703 * camera ID. This function is blocking until the operation completes or
704 * fails.
705 *
706 * The camera device has a higher priority accessing the flash unit. When
707 * there are any resource conflicts, such as open() is called to open a
708 * camera device, HAL module must notify the framework through
709 * camera_module_callbacks.torch_mode_status_change() that the
710 * torch mode has been turned off and the torch mode state has become
711 * TORCH_MODE_STATUS_RESOURCE_BUSY. When resources to turn on torch mode
712 * become available again, HAL module must notify the framework through
713 * camera_module_callbacks.torch_mode_status_change() that the torch mode
714 * state has become available for set_torch_mode() to be called.
715 *
716 * Version information (based on camera_module_t.common.module_api_version):
717 *
718 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3:
719 * Not provided by HAL module. Framework will not call this function.
720 *
721 * CAMERA_MODULE_API_VERSION_2_4:
722 * Valid to be called by the framework.
723 *
724 * Return values:
725 *
726 * 0: On a successful operation.
727 *
728 * -ENOSYS: The camera device does not support this operation. It is
729 * returned if and only if android.flash.info.available is
730 * false.
731 *
732 * -EBUSY: The flash unit or the resource needed to turn on the torch
733 * mode is busy, typically because the camera device is already
734 * in use, or some other camera device is using enough
735 * resources to make using the flash unit not possible.
736 *
737 * -EINVAL: camera_id is invalid.
738 *
739 */
740 int (*set_torch_mode)(const char* camera_id, bool on);
741
Alex Ray19b2cea2013-06-13 12:40:52 -0700742 /* reserved for future use */
Chien-Yu Chen30159172015-01-08 11:06:38 -0800743 void* reserved[6];
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800744} camera_module_t;
745
746__END_DECLS
747
748#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */