blob: 53b7361375b03be5e9e3bbd6ffdcf1143175be83 [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.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800110 */
111
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700112/**
113 * Predefined macros for currently-defined version numbers
114 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800115
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700116/**
117 * All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
118 * as CAMERA_MODULE_API_VERSION_1_0
119 */
120#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
121#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800122#define CAMERA_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1)
Alex Ray19b2cea2013-06-13 12:40:52 -0700123#define CAMERA_MODULE_API_VERSION_2_2 HARDWARE_MODULE_API_VERSION(2, 2)
Zhijun Hebcdebf32014-06-06 15:42:17 -0700124#define CAMERA_MODULE_API_VERSION_2_3 HARDWARE_MODULE_API_VERSION(2, 3)
Chien-Yu Chen30159172015-01-08 11:06:38 -0800125#define CAMERA_MODULE_API_VERSION_2_4 HARDWARE_MODULE_API_VERSION(2, 4)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700126
Chien-Yu Chen30159172015-01-08 11:06:38 -0800127#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_4
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700128
129/**
130 * All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
131 * as CAMERA_DEVICE_API_VERSION_1_0
132 */
133#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
134#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800135#define CAMERA_DEVICE_API_VERSION_2_1 HARDWARE_DEVICE_API_VERSION(2, 1)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800136#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
Eino-Ville Talvala9d518562013-07-30 14:58:31 -0700137#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800138#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
Zhijun Heebdf1282015-01-16 16:44:40 -0800139#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700140
Zhijun Heebdf1282015-01-16 16:44:40 -0800141// Device version 3.3 is current, older HAL camera device versions are not
Eino-Ville Talvalab5459832014-09-09 16:42:27 -0700142// recommended for new devices.
Zhijun Heebdf1282015-01-16 16:44:40 -0800143#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_3_3
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800144
145/**
James Dongd0ca70d2012-03-26 16:22:35 -0700146 * Defined in /system/media/camera/include/system/camera_metadata.h
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800147 */
148typedef struct camera_metadata camera_metadata_t;
149
Alex Ray9acc7402013-02-07 15:44:24 -0800150typedef struct camera_info {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800151 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800152 * The direction that the camera faces to. See system/core/include/system/camera.h
153 * for camera facing definitions.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800154 *
Zhijun He94e23b22015-01-12 14:45:33 -0800155 * Version information (based on camera_module_t.common.module_api_version):
156 *
157 * CAMERA_MODULE_API_VERSION_2_3 or lower:
158 *
159 * It should be CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
160 *
161 * CAMERA_MODULE_API_VERSION_2_4 or higher:
162 *
163 * It should be CAMERA_FACING_BACK, CAMERA_FACING_FRONT or
164 * CAMERA_FACING_EXTERNAL.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800165 */
166 int facing;
167
168 /**
169 * The orientation of the camera image. The value is the angle that the
170 * camera image needs to be rotated clockwise so it shows correctly on the
171 * display in its natural orientation. It should be 0, 90, 180, or 270.
172 *
173 * For example, suppose a device has a naturally tall screen. The
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800174 * back-facing camera sensor is mounted in landscape. You are looking at the
175 * screen. If the top side of the camera sensor is aligned with the right
176 * edge of the screen in natural orientation, the value should be 90. If the
177 * top side of a front-facing camera sensor is aligned with the right of the
178 * screen, the value should be 270.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800179 *
Zhijun He94e23b22015-01-12 14:45:33 -0800180 * Version information (based on camera_module_t.common.module_api_version):
181 *
182 * CAMERA_MODULE_API_VERSION_2_3 or lower:
183 *
184 * Valid in all camera_module versions.
185 *
186 * CAMERA_MODULE_API_VERSION_2_4 or higher:
187 *
188 * Valid if camera facing is CAMERA_FACING_BACK or CAMERA_FACING_FRONT,
189 * not valid if camera facing is CAMERA_FACING_EXTERNAL.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800190 */
191 int orientation;
192
193 /**
194 * The value of camera_device_t.common.version.
195 *
196 * Version information (based on camera_module_t.common.module_api_version):
197 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700198 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800199 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700200 * Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800201 * not read this field.
202 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800203 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800204 *
205 * Always valid
206 *
207 */
208 uint32_t device_version;
209
210 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800211 * The camera's fixed characteristics, which include all static camera metadata
212 * specified in system/media/camera/docs/docs.html. This should be a sorted metadata
213 * buffer, and may not be modified or freed by the caller. The pointer should remain
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800214 * valid for the lifetime of the camera module, and values in it may not
215 * change after it is returned by get_camera_info().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800216 *
217 * Version information (based on camera_module_t.common.module_api_version):
218 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700219 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800220 *
221 * Not valid. Extra characteristics are not available. Do not read this
222 * field.
223 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800224 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800225 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700226 * Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
227 * otherwise.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800228 *
229 */
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700230 const camera_metadata_t *static_camera_characteristics;
Alex Ray9acc7402013-02-07 15:44:24 -0800231} camera_info_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800232
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800233/**
234 * camera_device_status_t:
235 *
236 * The current status of the camera device, as provided by the HAL through the
237 * camera_module_callbacks.camera_device_status_change() call.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700238 *
239 * At module load time, the framework will assume all camera devices are in the
240 * CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke
241 * camera_module_callbacks::camera_device_status_change to inform the framework
242 * of any initially NOT_PRESENT devices.
243 *
244 * Allowed transitions:
245 * PRESENT -> NOT_PRESENT
246 * NOT_PRESENT -> ENUMERATING
247 * NOT_PRESENT -> PRESENT
248 * ENUMERATING -> PRESENT
249 * ENUMERATING -> NOT_PRESENT
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800250 */
251typedef enum camera_device_status {
252 /**
253 * The camera device is not currently connected, and opening it will return
Zhijun He94e23b22015-01-12 14:45:33 -0800254 * failure.
255 *
256 * Version information (based on camera_module_t.common.module_api_version):
257 *
258 * CAMERA_MODULE_API_VERSION_2_3 or lower:
259 *
260 * Calls to get_camera_info must still succeed, and provide the same information
261 * it would if the camera were connected.
262 *
263 * CAMERA_MODULE_API_VERSION_2_4:
264 *
265 * The camera device at this status must return -EINVAL for get_camera_info call,
266 * as the device is not connected.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800267 */
268 CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
269
270 /**
Zhijun He94e23b22015-01-12 14:45:33 -0800271 * The camera device is connected, and opening it will succeed.
272 *
273 * CAMERA_MODULE_API_VERSION_2_3 or lower:
274 *
275 * The information returned by get_camera_info cannot change due to this status
276 * change. By default, the framework will assume all devices are in this state.
277 *
278 * CAMERA_MODULE_API_VERSION_2_4:
279 *
280 * The information returned by get_camera_info will become valid after a device's
281 * status changes to this. By default, the framework will assume all devices are in
282 * this state.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800283 */
Igor Murashkin152b50f2013-03-18 13:30:14 -0700284 CAMERA_DEVICE_STATUS_PRESENT = 1,
285
286 /**
287 * The camera device is connected, but it is undergoing an enumeration and
Zhijun He94e23b22015-01-12 14:45:33 -0800288 * so opening the device will return -EBUSY.
289 *
290 * CAMERA_MODULE_API_VERSION_2_3 or lower:
291 *
292 * Calls to get_camera_info must still succeed, as if the camera was in the
293 * PRESENT status.
294 *
295 * CAMERA_MODULE_API_VERSION_2_4:
296 *
297 * The camera device at this status must return -EINVAL for get_camera_info for call,
298 * as the device is not ready.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700299 */
300 CAMERA_DEVICE_STATUS_ENUMERATING = 2,
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800301
302} camera_device_status_t;
303
304/**
Chien-Yu Chen30159172015-01-08 11:06:38 -0800305 * torch_mode_status_t:
306 *
307 * The current status of the torch mode, as provided by the HAL through the
308 * camera_module_callbacks.torch_mode_status_change() call.
309 *
310 * The torch mode status of a camera device is applicable only when the camera
311 * device is present. The framework will not call set_torch_mode() to turn on
312 * torch mode of a camera device if the camera device is not present. At module
313 * load time, the framework will assume torch modes are in the
314 * TORCH_MODE_STATUS_AVAILABLE state if the camera device is present and
315 * android.flash.info.available is reported as true via get_camera_info() call.
316 *
317 * The behaviors of the camera HAL module that the framework expects in the
318 * following situations when a camera device's status changes:
319 * 1. A previously-disconnected camera device becomes connected.
320 * After camera_module_callbacks::camera_device_status_change() is invoked
321 * to inform the framework that the camera device is present, the framework
322 * will assume the camera device's torch mode is in
323 * TORCH_MODE_STATUS_AVAILABLE state. The camera HAL module does not need
324 * to invoke camera_module_callbacks::torch_mode_status_change() unless the
325 * flash unit is unavailable to use by set_torch_mode().
326 *
327 * 2. A previously-connected camera becomes disconnected.
328 * After camera_module_callbacks::camera_device_status_change() is invoked
329 * to inform the framework that the camera device is not present, the
330 * framework will not call set_torch_mode() for the disconnected camera
331 * device until its flash unit becomes available again. The camera HAL
332 * module does not need to invoke
333 * camera_module_callbacks::torch_mode_status_change() separately to inform
334 * that the flash unit has become unavailable.
335 *
336 * 3. open() is called to open a camera device.
337 * The camera HAL module must invoke
338 * camera_module_callbacks::torch_mode_status_change() for all flash units
339 * that have entered TORCH_MODE_STATUS_RESOURCE_BUSY state and can not be
340 * turned on by calling set_torch_mode() anymore due to this open() call.
341 *
342 * 4. close() is called to close a camera device.
343 * The camera HAL module must invoke
344 * camera_module_callbacks::torch_mode_status_change() for all flash units
345 * that have entered TORCH_MODE_STATUS_AVAILABLE state and can be turned
346 * on by calling set_torch_mode() again because of enough resources freed
347 * up by this close() call.
348 *
349 * Note that the framework calling set_torch_mode() should not trigger any
350 * callbacks.
351 */
352typedef enum torch_mode_status {
353 /**
354 * The flash unit is available and the torch mode can be turned on by
355 * calling set_torch_mode(). By default, the framework will assume all
356 * flash units of all present camera devices are in this state if
357 * android.flash.info.available is reported as true via get_camera_info()
358 * call.
359 */
360 TORCH_MODE_STATUS_AVAILABLE = 0,
361
362 /**
363 * The flash unit is no longer available and the torch mode can not be
364 * turned on by calling set_torch_mode(). If the torch mode is on, it
365 * will be turned off by HAL before HAL calls torch_mode_status_change().
366 */
367 TORCH_MODE_STATUS_RESOURCE_BUSY = 1,
368
369} torch_mode_status_t;
370
371/**
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800372 * Callback functions for the camera HAL module to use to inform the framework
Chien-Yu Chen30159172015-01-08 11:06:38 -0800373 * of changes to the camera subsystem.
374 *
375 * Version information (based on camera_module_t.common.module_api_version):
376 *
377 * Each callback is called only by HAL modules implementing the indicated
378 * version or higher of the HAL module API interface.
379 *
380 * CAMERA_MODULE_API_VERSION_2_1:
381 * camera_device_status_change()
382 *
383 * CAMERA_MODULE_API_VERSION_2_4:
384 * torch_mode_status_change()
385
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800386 */
387typedef struct camera_module_callbacks {
388
389 /**
390 * camera_device_status_change:
391 *
392 * Callback to the framework to indicate that the state of a specific camera
393 * device has changed. At module load time, the framework will assume all
394 * camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
395 * must call this method to inform the framework of any initially
396 * NOT_PRESENT devices.
397 *
Chien-Yu Chen30159172015-01-08 11:06:38 -0800398 * This callback is added for CAMERA_MODULE_API_VERSION_2_1.
399 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800400 * camera_module_callbacks: The instance of camera_module_callbacks_t passed
401 * to the module with set_callbacks.
402 *
403 * camera_id: The ID of the camera device that has a new status.
404 *
405 * new_status: The new status code, one of the camera_device_status_t enums,
406 * or a platform-specific status.
407 *
408 */
409 void (*camera_device_status_change)(const struct camera_module_callbacks*,
410 int camera_id,
411 int new_status);
412
Chien-Yu Chen30159172015-01-08 11:06:38 -0800413 /**
414 * torch_mode_status_change:
415 *
416 * Callback to the framework to indicate that the state of the torch mode
417 * of the flash unit associated with a specific camera device has changed.
418 * At module load time, the framework will assume the torch modes are in
419 * the TORCH_MODE_STATUS_AVAILABLE state if android.flash.info.available
420 * is reported as true via get_camera_info() call.
421 *
422 * This callback is added for CAMERA_MODULE_API_VERSION_2_4.
423 *
424 * camera_module_callbacks: The instance of camera_module_callbacks_t
425 * passed to the module with set_callbacks.
426 *
427 * camera_id: The ID of camera device whose flash unit has a new torch mode
428 * status.
429 *
430 * new_status: The new status code, one of the torch_mode_status_t enums.
431 */
432 void (*torch_mode_status_change)(const struct camera_module_callbacks*,
433 const char* camera_id,
434 int new_status);
435
436
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800437} camera_module_callbacks_t;
438
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800439typedef struct camera_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700440 /**
441 * Common methods of the camera module. This *must* be the first member of
442 * camera_module as users of this structure will cast a hw_module_t to
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700443 * camera_module pointer in contexts where it's known the hw_module_t
444 * references a camera_module.
445 *
446 * The return values for common.methods->open for camera_module are:
447 *
448 * 0: On a successful open of the camera device.
449 *
450 * -ENODEV: The camera device cannot be opened due to an internal
451 * error.
452 *
453 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
454 * and/or the module is invalid.
455 *
456 * -EBUSY: The camera device was already opened for this camera id
457 * (by using this method or open_legacy),
458 * regardless of the device HAL version it was opened as.
459 *
460 * -EUSERS: The maximal number of camera devices that can be
461 * opened concurrently were opened already, either by
462 * this method or the open_legacy method.
463 *
464 * All other return values from common.methods->open will be treated as
465 * -ENODEV.
Stewart Miles84d35492014-05-01 09:03:27 -0700466 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800467 hw_module_t common;
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800468
469 /**
470 * get_number_of_cameras:
471 *
472 * Returns the number of camera devices accessible through the camera
473 * module. The camera devices are numbered 0 through N-1, where N is the
474 * value returned by this call. The name of the camera device for open() is
475 * simply the number converted to a string. That is, "0" for camera ID 0,
476 * "1" for camera ID 1.
477 *
Zhijun He94e23b22015-01-12 14:45:33 -0800478 * Version information (based on camera_module_t.common.module_api_version):
479 *
480 * CAMERA_MODULE_API_VERSION_2_3 or lower:
481 *
482 * The value here must be static, and cannot change after the first call
483 * to this method.
484 *
485 * CAMERA_MODULE_API_VERSION_2_4 or higher:
486 *
487 * The value here must be static, and must count only built-in cameras,
488 * which have CAMERA_FACING_BACK or CAMERA_FACING_FRONT camera facing values
489 * (camera_info.facing). The HAL must not include the external cameras
490 * (camera_info.facing == CAMERA_FACING_EXTERNAL) into the return value
491 * of this call. Frameworks will use camera_device_status_change callback
492 * to manage number of external cameras.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800493 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800494 int (*get_number_of_cameras)(void);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800495
496 /**
497 * get_camera_info:
498 *
499 * Return the static camera information for a given camera device. This
500 * information may not change for a camera device.
501 *
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700502 * Return values:
503 *
504 * 0: On a successful operation
505 *
506 * -ENODEV: The information cannot be provided due to an internal
507 * error.
508 *
509 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
510 * and/or the module is invalid.
Zhijun He94e23b22015-01-12 14:45:33 -0800511 *
512 * Version information (based on camera_module_t.common.module_api_version):
513 *
514 * CAMERA_MODULE_API_VERSION_2_4 or higher:
515 *
516 * When a camera is disconnected, its camera id becomes invalid. Calling this
517 * this method with this invalid camera id will get -EINVAL and NULL camera
518 * static metadata (camera_info.static_camera_characteristics).
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800519 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800520 int (*get_camera_info)(int camera_id, struct camera_info *info);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800521
522 /**
523 * set_callbacks:
524 *
525 * Provide callback function pointers to the HAL module to inform framework
526 * of asynchronous camera module events. The framework will call this
527 * function once after initial camera HAL module load, after the
528 * get_number_of_cameras() method is called for the first time, and before
529 * any other calls to the module.
530 *
531 * Version information (based on camera_module_t.common.module_api_version):
532 *
533 * CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
534 *
535 * Not provided by HAL module. Framework may not call this function.
536 *
537 * CAMERA_MODULE_API_VERSION_2_1:
538 *
539 * Valid to be called by the framework.
540 *
Eino-Ville Talvalac984be72014-07-24 16:44:56 -0700541 * Return values:
542 *
543 * 0: On a successful operation
544 *
545 * -ENODEV: The operation cannot be completed due to an internal
546 * error.
547 *
548 * -EINVAL: The input arguments are invalid, i.e. the callbacks are
549 * null
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800550 */
551 int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
552
Alex Ray19b2cea2013-06-13 12:40:52 -0700553 /**
554 * get_vendor_tag_ops:
555 *
556 * Get methods to query for vendor extension metadata tag information. The
557 * HAL should fill in all the vendor tag operation methods, or leave ops
558 * unchanged if no vendor tags are defined.
559 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800560 * The vendor_tag_ops structure used here is defined in:
561 * system/media/camera/include/system/vendor_tags.h
562 *
Alex Ray19b2cea2013-06-13 12:40:52 -0700563 * Version information (based on camera_module_t.common.module_api_version):
564 *
565 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1:
566 * Not provided by HAL module. Framework may not call this function.
567 *
568 * CAMERA_MODULE_API_VERSION_2_2:
569 * Valid to be called by the framework.
570 */
571 void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops);
572
Zhijun Hebcdebf32014-06-06 15:42:17 -0700573 /**
574 * open_legacy:
575 *
576 * Open a specific legacy camera HAL device if multiple device HAL API
577 * versions are supported by this camera HAL module. For example, if the
578 * camera module supports both CAMERA_DEVICE_API_VERSION_1_0 and
579 * CAMERA_DEVICE_API_VERSION_3_2 device API for the same camera id,
580 * framework can call this function to open the camera device as
581 * CAMERA_DEVICE_API_VERSION_1_0 device.
582 *
583 * This is an optional method. A Camera HAL module does not need to support
584 * more than one device HAL version per device, and such modules may return
585 * -ENOSYS for all calls to this method. For all older HAL device API
586 * versions that are not supported, it may return -EOPNOTSUPP. When above
587 * cases occur, The normal open() method (common.methods->open) will be
588 * used by the framework instead.
589 *
590 * Version information (based on camera_module_t.common.module_api_version):
591 *
592 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2:
593 * Not provided by HAL module. Framework will not call this function.
594 *
595 * CAMERA_MODULE_API_VERSION_2_3:
596 * Valid to be called by the framework.
597 *
598 * Return values:
599 *
600 * 0: On a successful open of the camera device.
601 *
602 * -ENOSYS This method is not supported.
603 *
604 * -EOPNOTSUPP: The requested HAL version is not supported by this method.
605 *
606 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
607 * and/or the module is invalid.
608 *
609 * -EBUSY: The camera device was already opened for this camera id
610 * (by using this method or common.methods->open method),
611 * regardless of the device HAL version it was opened as.
612 *
613 * -EUSERS: The maximal number of camera devices that can be
614 * opened concurrently were opened already, either by
615 * this method or common.methods->open method.
616 */
617 int (*open_legacy)(const struct hw_module_t* module, const char* id,
618 uint32_t halVersion, struct hw_device_t** device);
619
Chien-Yu Chen30159172015-01-08 11:06:38 -0800620 /**
621 * set_torch_mode:
622 *
623 * Turn on or off the torch mode of the flash unit associated with a given
624 * camera ID. This function is blocking until the operation completes or
625 * fails.
626 *
627 * The camera device has a higher priority accessing the flash unit. When
628 * there are any resource conflicts, such as open() is called to open a
629 * camera device, HAL module must notify the framework through
630 * camera_module_callbacks.torch_mode_status_change() that the
631 * torch mode has been turned off and the torch mode state has become
632 * TORCH_MODE_STATUS_RESOURCE_BUSY. When resources to turn on torch mode
633 * become available again, HAL module must notify the framework through
634 * camera_module_callbacks.torch_mode_status_change() that the torch mode
635 * state has become available for set_torch_mode() to be called.
636 *
637 * Version information (based on camera_module_t.common.module_api_version):
638 *
639 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3:
640 * Not provided by HAL module. Framework will not call this function.
641 *
642 * CAMERA_MODULE_API_VERSION_2_4:
643 * Valid to be called by the framework.
644 *
645 * Return values:
646 *
647 * 0: On a successful operation.
648 *
649 * -ENOSYS: The camera device does not support this operation. It is
650 * returned if and only if android.flash.info.available is
651 * false.
652 *
653 * -EBUSY: The flash unit or the resource needed to turn on the torch
654 * mode is busy, typically because the camera device is already
655 * in use, or some other camera device is using enough
656 * resources to make using the flash unit not possible.
657 *
658 * -EINVAL: camera_id is invalid.
659 *
660 */
661 int (*set_torch_mode)(const char* camera_id, bool on);
662
Alex Ray19b2cea2013-06-13 12:40:52 -0700663 /* reserved for future use */
Chien-Yu Chen30159172015-01-08 11:06:38 -0800664 void* reserved[6];
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800665} camera_module_t;
666
667__END_DECLS
668
669#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */