blob: edd1ada365f22df46e3e07906273e197bc894dac [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 Talvalaaee47822015-04-07 13:47:46 -0700116 *
117 * 4. Module initialization method. This will be called by the camera service
118 * right after the HAL module is loaded, to allow for one-time initialization
119 * of the HAL. It is called before any other module methods are invoked.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800120 */
121
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700122/**
123 * Predefined macros for currently-defined version numbers
124 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800125
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700126/**
127 * All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
128 * as CAMERA_MODULE_API_VERSION_1_0
129 */
130#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
131#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800132#define CAMERA_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1)
Alex Ray19b2cea2013-06-13 12:40:52 -0700133#define CAMERA_MODULE_API_VERSION_2_2 HARDWARE_MODULE_API_VERSION(2, 2)
Zhijun Hebcdebf32014-06-06 15:42:17 -0700134#define CAMERA_MODULE_API_VERSION_2_3 HARDWARE_MODULE_API_VERSION(2, 3)
Chien-Yu Chen30159172015-01-08 11:06:38 -0800135#define CAMERA_MODULE_API_VERSION_2_4 HARDWARE_MODULE_API_VERSION(2, 4)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700136
Chien-Yu Chen30159172015-01-08 11:06:38 -0800137#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_4
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700138
139/**
140 * All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
141 * as CAMERA_DEVICE_API_VERSION_1_0
142 */
Eino-Ville Talvalad4392022015-11-25 13:51:51 -0800143#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0) // DEPRECATED
144#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0) // NO LONGER SUPPORTED
145#define CAMERA_DEVICE_API_VERSION_2_1 HARDWARE_DEVICE_API_VERSION(2, 1) // NO LONGER SUPPORTED
Eino-Ville Talvala18782aa2016-12-19 16:35:29 -0800146#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0) // NO LONGER SUPPORTED
147#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1) // NO LONGER SUPPORTED
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800148#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
Zhijun Heebdf1282015-01-16 16:44:40 -0800149#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
Yin-Chia Yeh3e0b5f62015-12-07 16:31:09 -0800150#define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4)
Emilian Peeveec2ee92017-11-08 19:33:27 +0000151#define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700152
Emilian Peeveec2ee92017-11-08 19:33:27 +0000153// Device version 3.5 is current, older HAL camera device versions are not
Eino-Ville Talvalab5459832014-09-09 16:42:27 -0700154// recommended for new devices.
Emilian Peeveec2ee92017-11-08 19:33:27 +0000155#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_3_5
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800156
157/**
James Dongd0ca70d2012-03-26 16:22:35 -0700158 * Defined in /system/media/camera/include/system/camera_metadata.h
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800159 */
160typedef struct camera_metadata camera_metadata_t;
161
Alex Ray9acc7402013-02-07 15:44:24 -0800162typedef struct camera_info {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800163 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800164 * The direction that the camera faces to. See system/core/include/system/camera.h
165 * for camera facing definitions.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800166 *
Zhijun He94e23b22015-01-12 14:45:33 -0800167 * Version information (based on camera_module_t.common.module_api_version):
168 *
169 * CAMERA_MODULE_API_VERSION_2_3 or lower:
170 *
171 * It should be CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
172 *
173 * CAMERA_MODULE_API_VERSION_2_4 or higher:
174 *
175 * It should be CAMERA_FACING_BACK, CAMERA_FACING_FRONT or
176 * CAMERA_FACING_EXTERNAL.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800177 */
178 int facing;
179
180 /**
181 * The orientation of the camera image. The value is the angle that the
182 * camera image needs to be rotated clockwise so it shows correctly on the
183 * display in its natural orientation. It should be 0, 90, 180, or 270.
184 *
185 * For example, suppose a device has a naturally tall screen. The
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800186 * back-facing camera sensor is mounted in landscape. You are looking at the
187 * screen. If the top side of the camera sensor is aligned with the right
188 * edge of the screen in natural orientation, the value should be 90. If the
189 * top side of a front-facing camera sensor is aligned with the right of the
190 * screen, the value should be 270.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800191 *
Zhijun He94e23b22015-01-12 14:45:33 -0800192 * Version information (based on camera_module_t.common.module_api_version):
193 *
194 * CAMERA_MODULE_API_VERSION_2_3 or lower:
195 *
196 * Valid in all camera_module versions.
197 *
198 * CAMERA_MODULE_API_VERSION_2_4 or higher:
199 *
200 * Valid if camera facing is CAMERA_FACING_BACK or CAMERA_FACING_FRONT,
201 * not valid if camera facing is CAMERA_FACING_EXTERNAL.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800202 */
203 int orientation;
204
205 /**
206 * The value of camera_device_t.common.version.
207 *
208 * Version information (based on camera_module_t.common.module_api_version):
209 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700210 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800211 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700212 * Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800213 * not read this field.
214 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800215 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800216 *
217 * Always valid
218 *
219 */
220 uint32_t device_version;
221
222 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800223 * The camera's fixed characteristics, which include all static camera metadata
224 * specified in system/media/camera/docs/docs.html. This should be a sorted metadata
225 * buffer, and may not be modified or freed by the caller. The pointer should remain
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800226 * valid for the lifetime of the camera module, and values in it may not
227 * change after it is returned by get_camera_info().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800228 *
229 * Version information (based on camera_module_t.common.module_api_version):
230 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700231 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800232 *
233 * Not valid. Extra characteristics are not available. Do not read this
234 * field.
235 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800236 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800237 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700238 * Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
239 * otherwise.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800240 *
241 */
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700242 const camera_metadata_t *static_camera_characteristics;
Ruben Brunk0388bcd2015-01-16 14:29:21 -0800243
244 /**
Ruben Brunk1fa09022015-03-10 11:53:12 -0700245 * The total resource "cost" of using this camera, represented as an integer
246 * value in the range [0, 100] where 100 represents total usage of the shared
247 * resource that is the limiting bottleneck of the camera subsystem. This may
248 * be a very rough estimate, and is used as a hint to the camera service to
249 * determine when to disallow multiple applications from simultaneously
250 * opening different cameras advertised by the camera service.
Ruben Brunk0388bcd2015-01-16 14:29:21 -0800251 *
252 * The camera service must be able to simultaneously open and use any
253 * combination of camera devices exposed by the HAL where the sum of
254 * the resource costs of these cameras is <= 100. For determining cost,
255 * each camera device must be assumed to be configured and operating at
256 * the maximally resource-consuming framerate and stream size settings
257 * available in the configuration settings exposed for that device through
258 * the camera metadata.
259 *
Ruben Brunk1fa09022015-03-10 11:53:12 -0700260 * The camera service may still attempt to simultaneously open combinations
261 * of camera devices with a total resource cost > 100. This may succeed or
262 * fail. If this succeeds, combinations of configurations that are not
263 * supported due to resource constraints from having multiple open devices
264 * should fail during the configure calls. If the total resource cost is
265 * <= 100, open and configure should never fail for any stream configuration
266 * settings or other device capabilities that would normally succeed for a
267 * device when it is the only open camera device.
268 *
269 * This field will be used to determine whether background applications are
270 * allowed to use this camera device while other applications are using other
271 * camera devices. Note: multiple applications will never be allowed by the
272 * camera service to simultaneously open the same camera device.
273 *
274 * Example use cases:
275 *
276 * Ex. 1: Camera Device 0 = Back Camera
277 * Camera Device 1 = Front Camera
278 * - Using both camera devices causes a large framerate slowdown due to
279 * limited ISP bandwidth.
280 *
281 * Configuration:
282 *
283 * Camera Device 0 - resource_cost = 51
284 * conflicting_devices = null
285 * Camera Device 1 - resource_cost = 51
286 * conflicting_devices = null
287 *
288 * Result:
289 *
290 * Since the sum of the resource costs is > 100, if a higher-priority
291 * application has either device open, no lower-priority applications will be
292 * allowed by the camera service to open either device. If a lower-priority
293 * application is using a device that a higher-priority subsequently attempts
294 * to open, the lower-priority application will be forced to disconnect the
295 * the device.
296 *
297 * If the highest-priority application chooses, it may still attempt to open
298 * both devices (since these devices are not listed as conflicting in the
299 * conflicting_devices fields), but usage of these devices may fail in the
300 * open or configure calls.
301 *
302 * Ex. 2: Camera Device 0 = Left Back Camera
303 * Camera Device 1 = Right Back Camera
304 * Camera Device 2 = Combined stereo camera using both right and left
305 * back camera sensors used by devices 0, and 1
306 * Camera Device 3 = Front Camera
307 * - Due to do hardware constraints, up to two cameras may be open at once. The
308 * combined stereo camera may never be used at the same time as either of the
309 * two back camera devices (device 0, 1), and typically requires too much
310 * bandwidth to use at the same time as the front camera (device 3).
311 *
312 * Configuration:
313 *
314 * Camera Device 0 - resource_cost = 50
315 * conflicting_devices = { 2 }
316 * Camera Device 1 - resource_cost = 50
317 * conflicting_devices = { 2 }
318 * Camera Device 2 - resource_cost = 100
319 * conflicting_devices = { 0, 1 }
320 * Camera Device 3 - resource_cost = 50
321 * conflicting_devices = null
322 *
323 * Result:
324 *
325 * Based on the conflicting_devices fields, the camera service guarantees that
326 * the following sets of open devices will never be allowed: { 1, 2 }, { 0, 2 }.
327 *
328 * Based on the resource_cost fields, if a high-priority foreground application
329 * is using camera device 0, a background application would be allowed to open
330 * camera device 1 or 3 (but would be forced to disconnect it again if the
331 * foreground application opened another device).
332 *
333 * The highest priority application may still attempt to simultaneously open
334 * devices 0, 2, and 3, but the HAL may fail in open or configure calls for
335 * this combination.
336 *
337 * Ex. 3: Camera Device 0 = Back Camera
338 * Camera Device 1 = Front Camera
339 * Camera Device 2 = Low-power Front Camera that uses the same
340 * sensor as device 1, but only exposes image stream
341 * resolutions that can be used in low-power mode
342 * - Using both front cameras (device 1, 2) at the same time is impossible due
343 * a shared physical sensor. Using the back and "high-power" front camera
344 * (device 1) may be impossible for some stream configurations due to hardware
345 * limitations, but the "low-power" front camera option may always be used as
346 * it has special dedicated hardware.
347 *
348 * Configuration:
349 *
350 * Camera Device 0 - resource_cost = 100
351 * conflicting_devices = null
352 * Camera Device 1 - resource_cost = 100
353 * conflicting_devices = { 2 }
354 * Camera Device 2 - resource_cost = 0
355 * conflicting_devices = { 1 }
356 * Result:
357 *
358 * Based on the conflicting_devices fields, the camera service guarantees that
359 * the following sets of open devices will never be allowed: { 1, 2 }.
360 *
361 * Based on the resource_cost fields, only the highest priority application
362 * may attempt to open both device 0 and 1 at the same time. If a higher-priority
363 * application is not using device 1 or 2, a low-priority background application
364 * may open device 2 (but will be forced to disconnect it if a higher-priority
365 * application subsequently opens device 1 or 2).
Ruben Brunk0388bcd2015-01-16 14:29:21 -0800366 *
367 * Version information (based on camera_module_t.common.module_api_version):
368 *
369 * CAMERA_MODULE_API_VERSION_2_3 or lower:
370 *
371 * Not valid. Can be assumed to be 100. Do not read this field.
372 *
373 * CAMERA_MODULE_API_VERSION_2_4 or higher:
374 *
375 * Always valid.
376 */
377 int resource_cost;
378
379 /**
380 * An array of camera device IDs represented as NULL-terminated strings
381 * indicating other devices that cannot be simultaneously opened while this
382 * camera device is in use.
383 *
384 * This field is intended to be used to indicate that this camera device
385 * is a composite of several other camera devices, or otherwise has
386 * hardware dependencies that prohibit simultaneous usage. If there are no
387 * dependencies, a NULL may be returned in this field to indicate this.
388 *
389 * The camera service will never simultaneously open any of the devices
390 * in this list while this camera device is open.
391 *
Ruben Brunk1fa09022015-03-10 11:53:12 -0700392 * The strings pointed to in this field will not be cleaned up by the camera
393 * service, and must remain while this device is plugged in.
394 *
Ruben Brunk0388bcd2015-01-16 14:29:21 -0800395 * Version information (based on camera_module_t.common.module_api_version):
396 *
397 * CAMERA_MODULE_API_VERSION_2_3 or lower:
398 *
399 * Not valid. Can be assumed to be NULL. Do not read this field.
400 *
401 * CAMERA_MODULE_API_VERSION_2_4 or higher:
402 *
403 * Always valid.
404 */
405 char** conflicting_devices;
406
407 /**
408 * The length of the array given in the conflicting_devices field.
409 *
410 * Version information (based on camera_module_t.common.module_api_version):
411 *
412 * CAMERA_MODULE_API_VERSION_2_3 or lower:
413 *
414 * Not valid. Can be assumed to be 0. Do not read this field.
415 *
416 * CAMERA_MODULE_API_VERSION_2_4 or higher:
417 *
418 * Always valid.
419 */
420 size_t conflicting_devices_length;
421
Alex Ray9acc7402013-02-07 15:44:24 -0800422} camera_info_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800423
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800424/**
425 * camera_device_status_t:
426 *
427 * The current status of the camera device, as provided by the HAL through the
428 * camera_module_callbacks.camera_device_status_change() call.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700429 *
430 * At module load time, the framework will assume all camera devices are in the
431 * CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke
432 * camera_module_callbacks::camera_device_status_change to inform the framework
433 * of any initially NOT_PRESENT devices.
434 *
435 * Allowed transitions:
436 * PRESENT -> NOT_PRESENT
437 * NOT_PRESENT -> ENUMERATING
438 * NOT_PRESENT -> PRESENT
439 * ENUMERATING -> PRESENT
440 * ENUMERATING -> NOT_PRESENT
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800441 */
442typedef enum camera_device_status {
443 /**
444 * The camera device is not currently connected, and opening it will return
Zhijun He94e23b22015-01-12 14:45:33 -0800445 * failure.
446 *
447 * Version information (based on camera_module_t.common.module_api_version):
448 *
449 * CAMERA_MODULE_API_VERSION_2_3 or lower:
450 *
451 * Calls to get_camera_info must still succeed, and provide the same information
452 * it would if the camera were connected.
453 *
454 * CAMERA_MODULE_API_VERSION_2_4:
455 *
456 * The camera device at this status must return -EINVAL for get_camera_info call,
457 * as the device is not connected.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800458 */
459 CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
460
461 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800462 * The camera device is connected, and opening it will succeed.
463 *
464 * CAMERA_MODULE_API_VERSION_2_3 or lower:
465 *
466 * The information returned by get_camera_info cannot change due to this status
467 * change. By default, the framework will assume all devices are in this state.
468 *
469 * CAMERA_MODULE_API_VERSION_2_4:
470 *
471 * The information returned by get_camera_info will become valid after a device's
472 * status changes to this. By default, the framework will assume all devices are in
473 * this state.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800474 */
Igor Murashkin152b50f2013-03-18 13:30:14 -0700475 CAMERA_DEVICE_STATUS_PRESENT = 1,
476
477 /**
478 * The camera device is connected, but it is undergoing an enumeration and
Zhijun He94e23b22015-01-12 14:45:33 -0800479 * so opening the device will return -EBUSY.
480 *
481 * CAMERA_MODULE_API_VERSION_2_3 or lower:
482 *
483 * Calls to get_camera_info must still succeed, as if the camera was in the
484 * PRESENT status.
485 *
486 * CAMERA_MODULE_API_VERSION_2_4:
487 *
488 * The camera device at this status must return -EINVAL for get_camera_info for call,
489 * as the device is not ready.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700490 */
491 CAMERA_DEVICE_STATUS_ENUMERATING = 2,
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800492
493} camera_device_status_t;
494
495/**
Chien-Yu Chen30159172015-01-08 11:06:38 -0800496 * torch_mode_status_t:
497 *
498 * The current status of the torch mode, as provided by the HAL through the
499 * camera_module_callbacks.torch_mode_status_change() call.
500 *
501 * The torch mode status of a camera device is applicable only when the camera
502 * device is present. The framework will not call set_torch_mode() to turn on
503 * torch mode of a camera device if the camera device is not present. At module
504 * load time, the framework will assume torch modes are in the
Chien-Yu Chen5c6230e2015-06-03 13:36:33 -0700505 * TORCH_MODE_STATUS_AVAILABLE_OFF state if the camera device is present and
Chien-Yu Chen30159172015-01-08 11:06:38 -0800506 * android.flash.info.available is reported as true via get_camera_info() call.
507 *
508 * The behaviors of the camera HAL module that the framework expects in the
509 * following situations when a camera device's status changes:
510 * 1. A previously-disconnected camera device becomes connected.
511 * After camera_module_callbacks::camera_device_status_change() is invoked
512 * to inform the framework that the camera device is present, the framework
513 * will assume the camera device's torch mode is in
Chien-Yu Chen5c6230e2015-06-03 13:36:33 -0700514 * TORCH_MODE_STATUS_AVAILABLE_OFF state. The camera HAL module does not need
Chien-Yu Chen30159172015-01-08 11:06:38 -0800515 * to invoke camera_module_callbacks::torch_mode_status_change() unless the
516 * flash unit is unavailable to use by set_torch_mode().
517 *
518 * 2. A previously-connected camera becomes disconnected.
519 * After camera_module_callbacks::camera_device_status_change() is invoked
520 * to inform the framework that the camera device is not present, the
521 * framework will not call set_torch_mode() for the disconnected camera
522 * device until its flash unit becomes available again. The camera HAL
523 * module does not need to invoke
524 * camera_module_callbacks::torch_mode_status_change() separately to inform
525 * that the flash unit has become unavailable.
526 *
527 * 3. open() is called to open 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_NOT_AVAILABLE state and can not be
Chien-Yu Chen30159172015-01-08 11:06:38 -0800531 * turned on by calling set_torch_mode() anymore due to this open() call.
Chien-Yu Chen5c6230e2015-06-03 13:36:33 -0700532 * open() must not trigger TORCH_MODE_STATUS_AVAILABLE_OFF before
533 * TORCH_MODE_STATUS_NOT_AVAILABLE for all flash units that have become
534 * unavailable.
Chien-Yu Chen30159172015-01-08 11:06:38 -0800535 *
536 * 4. close() is called to close a camera device.
537 * The camera HAL module must invoke
538 * camera_module_callbacks::torch_mode_status_change() for all flash units
Chien-Yu Chen5c6230e2015-06-03 13:36:33 -0700539 * that have entered TORCH_MODE_STATUS_AVAILABLE_OFF state and can be turned
Chien-Yu Chen30159172015-01-08 11:06:38 -0800540 * on by calling set_torch_mode() again because of enough resources freed
541 * up by this close() call.
542 *
Chien-Yu Chen85585102015-02-25 14:50:13 -0800543 * Note that the framework calling set_torch_mode() successfully must trigger
Chien-Yu Chen5c6230e2015-06-03 13:36:33 -0700544 * TORCH_MODE_STATUS_AVAILABLE_OFF or TORCH_MODE_STATUS_AVAILABLE_ON callback
545 * for the given camera device. Additionally it must trigger
546 * TORCH_MODE_STATUS_AVAILABLE_OFF callbacks for other previously-on torch
547 * modes if HAL cannot keep multiple torch modes on simultaneously.
Chien-Yu Chen30159172015-01-08 11:06:38 -0800548 */
549typedef enum torch_mode_status {
Chien-Yu Chen30159172015-01-08 11:06:38 -0800550
551 /**
552 * The flash unit is no longer available and the torch mode can not be
553 * turned on by calling set_torch_mode(). If the torch mode is on, it
554 * will be turned off by HAL before HAL calls torch_mode_status_change().
555 */
Chien-Yu Chen85585102015-02-25 14:50:13 -0800556 TORCH_MODE_STATUS_NOT_AVAILABLE = 0,
Chien-Yu Chen30159172015-01-08 11:06:38 -0800557
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800558 /**
Chien-Yu Chen85585102015-02-25 14:50:13 -0800559 * A torch mode has become off and available to be turned on via
560 * set_torch_mode(). This may happen in the following
561 * cases:
562 * 1. After the resources to turn on the torch mode have become available.
563 * 2. After set_torch_mode() is called to turn off the torch mode.
564 * 3. After the framework turned on the torch mode of some other camera
565 * device and HAL had to turn off the torch modes of any camera devices
566 * that were previously on.
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800567 */
Chien-Yu Chen85585102015-02-25 14:50:13 -0800568 TORCH_MODE_STATUS_AVAILABLE_OFF = 1,
569
570 /**
571 * A torch mode has become on and available to be turned off via
572 * set_torch_mode(). This can happen only after set_torch_mode() is called
573 * to turn on the torch mode.
574 */
575 TORCH_MODE_STATUS_AVAILABLE_ON = 2,
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800576
Chien-Yu Chen30159172015-01-08 11:06:38 -0800577} torch_mode_status_t;
578
579/**
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800580 * Callback functions for the camera HAL module to use to inform the framework
Chien-Yu Chen30159172015-01-08 11:06:38 -0800581 * of changes to the camera subsystem.
582 *
583 * Version information (based on camera_module_t.common.module_api_version):
584 *
585 * Each callback is called only by HAL modules implementing the indicated
586 * version or higher of the HAL module API interface.
587 *
588 * CAMERA_MODULE_API_VERSION_2_1:
589 * camera_device_status_change()
590 *
591 * CAMERA_MODULE_API_VERSION_2_4:
592 * torch_mode_status_change()
593
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800594 */
595typedef struct camera_module_callbacks {
596
597 /**
598 * camera_device_status_change:
599 *
600 * Callback to the framework to indicate that the state of a specific camera
601 * device has changed. At module load time, the framework will assume all
602 * camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
603 * must call this method to inform the framework of any initially
604 * NOT_PRESENT devices.
605 *
Chien-Yu Chen30159172015-01-08 11:06:38 -0800606 * This callback is added for CAMERA_MODULE_API_VERSION_2_1.
607 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800608 * camera_module_callbacks: The instance of camera_module_callbacks_t passed
609 * to the module with set_callbacks.
610 *
611 * camera_id: The ID of the camera device that has a new status.
612 *
613 * new_status: The new status code, one of the camera_device_status_t enums,
614 * or a platform-specific status.
615 *
616 */
617 void (*camera_device_status_change)(const struct camera_module_callbacks*,
618 int camera_id,
619 int new_status);
620
Chien-Yu Chen30159172015-01-08 11:06:38 -0800621 /**
622 * torch_mode_status_change:
623 *
624 * Callback to the framework to indicate that the state of the torch mode
625 * of the flash unit associated with a specific camera device has changed.
626 * At module load time, the framework will assume the torch modes are in
Chien-Yu Chen5c6230e2015-06-03 13:36:33 -0700627 * the TORCH_MODE_STATUS_AVAILABLE_OFF state if android.flash.info.available
Chien-Yu Chen30159172015-01-08 11:06:38 -0800628 * is reported as true via get_camera_info() call.
629 *
630 * This callback is added for CAMERA_MODULE_API_VERSION_2_4.
631 *
632 * camera_module_callbacks: The instance of camera_module_callbacks_t
633 * passed to the module with set_callbacks.
634 *
635 * camera_id: The ID of camera device whose flash unit has a new torch mode
636 * status.
637 *
638 * new_status: The new status code, one of the torch_mode_status_t enums.
639 */
640 void (*torch_mode_status_change)(const struct camera_module_callbacks*,
641 const char* camera_id,
642 int new_status);
643
644
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800645} camera_module_callbacks_t;
646
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800647typedef struct camera_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700648 /**
649 * Common methods of the camera module. This *must* be the first member of
650 * camera_module as users of this structure will cast a hw_module_t to
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700651 * camera_module pointer in contexts where it's known the hw_module_t
652 * references a camera_module.
653 *
654 * The return values for common.methods->open for camera_module are:
655 *
656 * 0: On a successful open of the camera device.
657 *
658 * -ENODEV: The camera device cannot be opened due to an internal
659 * error.
660 *
661 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
662 * and/or the module is invalid.
663 *
664 * -EBUSY: The camera device was already opened for this camera id
665 * (by using this method or open_legacy),
666 * regardless of the device HAL version it was opened as.
667 *
668 * -EUSERS: The maximal number of camera devices that can be
669 * opened concurrently were opened already, either by
670 * this method or the open_legacy method.
671 *
672 * All other return values from common.methods->open will be treated as
673 * -ENODEV.
Stewart Miles84d35492014-05-01 09:03:27 -0700674 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800675 hw_module_t common;
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800676
677 /**
678 * get_number_of_cameras:
679 *
680 * Returns the number of camera devices accessible through the camera
681 * module. The camera devices are numbered 0 through N-1, where N is the
682 * value returned by this call. The name of the camera device for open() is
683 * simply the number converted to a string. That is, "0" for camera ID 0,
684 * "1" for camera ID 1.
685 *
Zhijun He94e23b22015-01-12 14:45:33 -0800686 * Version information (based on camera_module_t.common.module_api_version):
687 *
688 * CAMERA_MODULE_API_VERSION_2_3 or lower:
689 *
690 * The value here must be static, and cannot change after the first call
691 * to this method.
692 *
693 * CAMERA_MODULE_API_VERSION_2_4 or higher:
694 *
695 * The value here must be static, and must count only built-in cameras,
696 * which have CAMERA_FACING_BACK or CAMERA_FACING_FRONT camera facing values
697 * (camera_info.facing). The HAL must not include the external cameras
698 * (camera_info.facing == CAMERA_FACING_EXTERNAL) into the return value
699 * of this call. Frameworks will use camera_device_status_change callback
700 * to manage number of external cameras.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800701 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800702 int (*get_number_of_cameras)(void);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800703
704 /**
705 * get_camera_info:
706 *
707 * Return the static camera information for a given camera device. This
708 * information may not change for a camera device.
709 *
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700710 * Return values:
711 *
712 * 0: On a successful operation
713 *
714 * -ENODEV: The information cannot be provided due to an internal
715 * error.
716 *
717 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
718 * and/or the module is invalid.
Zhijun He94e23b22015-01-12 14:45:33 -0800719 *
720 * Version information (based on camera_module_t.common.module_api_version):
721 *
722 * CAMERA_MODULE_API_VERSION_2_4 or higher:
723 *
724 * When a camera is disconnected, its camera id becomes invalid. Calling this
725 * this method with this invalid camera id will get -EINVAL and NULL camera
726 * static metadata (camera_info.static_camera_characteristics).
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800727 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800728 int (*get_camera_info)(int camera_id, struct camera_info *info);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800729
730 /**
731 * set_callbacks:
732 *
733 * Provide callback function pointers to the HAL module to inform framework
734 * of asynchronous camera module events. The framework will call this
735 * function once after initial camera HAL module load, after the
736 * get_number_of_cameras() method is called for the first time, and before
737 * any other calls to the module.
738 *
739 * Version information (based on camera_module_t.common.module_api_version):
740 *
741 * CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
742 *
743 * Not provided by HAL module. Framework may not call this function.
744 *
745 * CAMERA_MODULE_API_VERSION_2_1:
746 *
747 * Valid to be called by the framework.
748 *
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700749 * Return values:
750 *
751 * 0: On a successful operation
752 *
753 * -ENODEV: The operation cannot be completed due to an internal
754 * error.
755 *
756 * -EINVAL: The input arguments are invalid, i.e. the callbacks are
757 * null
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800758 */
759 int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
760
Alex Ray19b2cea2013-06-13 12:40:52 -0700761 /**
762 * get_vendor_tag_ops:
763 *
764 * Get methods to query for vendor extension metadata tag information. The
765 * HAL should fill in all the vendor tag operation methods, or leave ops
766 * unchanged if no vendor tags are defined.
767 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800768 * The vendor_tag_ops structure used here is defined in:
769 * system/media/camera/include/system/vendor_tags.h
770 *
Alex Ray19b2cea2013-06-13 12:40:52 -0700771 * Version information (based on camera_module_t.common.module_api_version):
772 *
773 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1:
774 * Not provided by HAL module. Framework may not call this function.
775 *
776 * CAMERA_MODULE_API_VERSION_2_2:
777 * Valid to be called by the framework.
778 */
779 void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops);
780
Zhijun Hebcdebf32014-06-06 15:42:17 -0700781 /**
782 * open_legacy:
783 *
784 * Open a specific legacy camera HAL device if multiple device HAL API
785 * versions are supported by this camera HAL module. For example, if the
786 * camera module supports both CAMERA_DEVICE_API_VERSION_1_0 and
787 * CAMERA_DEVICE_API_VERSION_3_2 device API for the same camera id,
788 * framework can call this function to open the camera device as
789 * CAMERA_DEVICE_API_VERSION_1_0 device.
790 *
791 * This is an optional method. A Camera HAL module does not need to support
792 * more than one device HAL version per device, and such modules may return
793 * -ENOSYS for all calls to this method. For all older HAL device API
794 * versions that are not supported, it may return -EOPNOTSUPP. When above
795 * cases occur, The normal open() method (common.methods->open) will be
796 * used by the framework instead.
797 *
798 * Version information (based on camera_module_t.common.module_api_version):
799 *
800 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2:
801 * Not provided by HAL module. Framework will not call this function.
802 *
803 * CAMERA_MODULE_API_VERSION_2_3:
804 * Valid to be called by the framework.
805 *
806 * Return values:
807 *
808 * 0: On a successful open of the camera device.
809 *
810 * -ENOSYS This method is not supported.
811 *
812 * -EOPNOTSUPP: The requested HAL version is not supported by this method.
813 *
814 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
815 * and/or the module is invalid.
816 *
817 * -EBUSY: The camera device was already opened for this camera id
818 * (by using this method or common.methods->open method),
819 * regardless of the device HAL version it was opened as.
820 *
821 * -EUSERS: The maximal number of camera devices that can be
822 * opened concurrently were opened already, either by
823 * this method or common.methods->open method.
824 */
825 int (*open_legacy)(const struct hw_module_t* module, const char* id,
826 uint32_t halVersion, struct hw_device_t** device);
827
Chien-Yu Chen30159172015-01-08 11:06:38 -0800828 /**
829 * set_torch_mode:
830 *
831 * Turn on or off the torch mode of the flash unit associated with a given
Chien-Yu Chen85585102015-02-25 14:50:13 -0800832 * camera ID. If the operation is successful, HAL must notify the framework
833 * torch state by invoking
834 * camera_module_callbacks.torch_mode_status_change() with the new state.
Chien-Yu Chen30159172015-01-08 11:06:38 -0800835 *
836 * The camera device has a higher priority accessing the flash unit. When
837 * there are any resource conflicts, such as open() is called to open a
838 * camera device, HAL module must notify the framework through
839 * camera_module_callbacks.torch_mode_status_change() that the
840 * torch mode has been turned off and the torch mode state has become
Chien-Yu Chen85585102015-02-25 14:50:13 -0800841 * TORCH_MODE_STATUS_NOT_AVAILABLE. When resources to turn on torch mode
Chien-Yu Chen30159172015-01-08 11:06:38 -0800842 * become available again, HAL module must notify the framework through
843 * camera_module_callbacks.torch_mode_status_change() that the torch mode
Chien-Yu Chen5c6230e2015-06-03 13:36:33 -0700844 * state has become TORCH_MODE_STATUS_AVAILABLE_OFF for set_torch_mode() to
845 * be called.
Chien-Yu Chen30159172015-01-08 11:06:38 -0800846 *
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800847 * When the framework calls set_torch_mode() to turn on the torch mode of a
848 * flash unit, if HAL cannot keep multiple torch modes on simultaneously,
849 * HAL should turn off the torch mode that was turned on by
850 * a previous set_torch_mode() call and notify the framework that the torch
Chien-Yu Chen5c6230e2015-06-03 13:36:33 -0700851 * mode state of that flash unit has become TORCH_MODE_STATUS_AVAILABLE_OFF.
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800852 *
Chien-Yu Chen30159172015-01-08 11:06:38 -0800853 * Version information (based on camera_module_t.common.module_api_version):
854 *
855 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3:
856 * Not provided by HAL module. Framework will not call this function.
857 *
858 * CAMERA_MODULE_API_VERSION_2_4:
859 * Valid to be called by the framework.
860 *
861 * Return values:
862 *
863 * 0: On a successful operation.
864 *
865 * -ENOSYS: The camera device does not support this operation. It is
866 * returned if and only if android.flash.info.available is
867 * false.
868 *
Chien-Yu Chen273def32015-02-11 11:31:12 -0800869 * -EBUSY: The camera device is already in use.
870 *
871 * -EUSERS: The resources needed to turn on the torch mode are not
872 * available, typically because other camera devices are
873 * holding the resources to make using the flash unit not
874 * possible.
Chien-Yu Chen30159172015-01-08 11:06:38 -0800875 *
876 * -EINVAL: camera_id is invalid.
877 *
878 */
Chien-Yu Chen46edf1a2015-01-29 15:12:47 -0800879 int (*set_torch_mode)(const char* camera_id, bool enabled);
Chien-Yu Chen30159172015-01-08 11:06:38 -0800880
Eino-Ville Talvalaaee47822015-04-07 13:47:46 -0700881 /**
882 * init:
883 *
884 * This method is called by the camera service before any other methods
885 * are invoked, right after the camera HAL library has been successfully
886 * loaded. It may be left as NULL by the HAL module, if no initialization
887 * in needed.
888 *
889 * It can be used by HAL implementations to perform initialization and
890 * other one-time operations.
891 *
892 * Version information (based on camera_module_t.common.module_api_version):
893 *
894 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3:
895 * Not provided by HAL module. Framework will not call this function.
896 *
897 * CAMERA_MODULE_API_VERSION_2_4:
898 * If not NULL, will always be called by the framework once after the HAL
899 * module is loaded, before any other HAL module method is called.
900 *
901 * Return values:
902 *
903 * 0: On a successful operation.
904 *
905 * -ENODEV: Initialization cannot be completed due to an internal
906 * error. The HAL must be assumed to be in a nonfunctional
907 * state.
908 *
909 */
910 int (*init)();
911
Alex Ray19b2cea2013-06-13 12:40:52 -0700912 /* reserved for future use */
Eino-Ville Talvalaaee47822015-04-07 13:47:46 -0700913 void* reserved[5];
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800914} camera_module_t;
915
916__END_DECLS
917
918#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */