blob: a2171ce3136ca6e4b545a95a411443ba9161d539 [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>
23#include <sys/cdefs.h>
24#include <sys/types.h>
25#include <cutils/native_handle.h>
26#include <system/camera.h>
27#include <hardware/hardware.h>
28#include <hardware/gralloc.h>
29
30__BEGIN_DECLS
31
32/**
33 * The id of this module
34 */
35#define CAMERA_HARDWARE_MODULE_ID "camera"
36
37/**
38 * Module versioning information for the Camera hardware module, based on
39 * camera_module_t.common.module_api_version. The two most significant hex
40 * digits represent the major version, and the two least significant represent
41 * the minor version.
42 *
43 *******************************************************************************
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070044 * Versions: 0.X - 1.X [CAMERA_MODULE_API_VERSION_1_0]
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080045 *
46 * Camera modules that report these version numbers implement the initial
47 * camera module HAL interface. All camera devices openable through this
48 * module support only version 1 of the camera device HAL. The device_version
49 * and static_camera_characteristics fields of camera_info are not valid. Only
50 * the android.hardware.Camera API can be supported by this module and its
51 * devices.
52 *
53 *******************************************************************************
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070054 * Version: 2.0 [CAMERA_MODULE_API_VERSION_2_0]
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080055 *
56 * Camera modules that report this version number implement the second version
57 * of the camera module HAL interface. Camera devices openable through this
58 * module may support either version 1.0 or version 2.0 of the camera device
59 * HAL interface. The device_version field of camera_info is always valid; the
60 * static_camera_characteristics field of camera_info is valid if the
61 * device_version field is 2.0 or higher.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -080062 *
63 *******************************************************************************
64 * Version: 2.1 [CAMERA_MODULE_API_VERSION_2_1]
65 *
66 * This camera module version adds support for asynchronous callbacks to the
67 * framework from the camera HAL module, which is used to notify the framework
68 * about changes to the camera module state. Modules that provide a valid
69 * set_callbacks() method must report at least this version number.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080070 */
71
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070072/**
73 * Predefined macros for currently-defined version numbers
74 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080075
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070076/**
77 * All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
78 * as CAMERA_MODULE_API_VERSION_1_0
79 */
80#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
81#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -080082#define CAMERA_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070083
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -080084#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_1
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070085
86/**
87 * All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
88 * as CAMERA_DEVICE_API_VERSION_1_0
89 */
90#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
91#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -080092#define CAMERA_DEVICE_API_VERSION_2_1 HARDWARE_DEVICE_API_VERSION(2, 1)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080093#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
Eino-Ville Talvala9d518562013-07-30 14:58:31 -070094#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070095
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -080096// Device version 2.x is outdated; device version 3.0 is experimental
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070097#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_1_0
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080098
99/**
James Dongd0ca70d2012-03-26 16:22:35 -0700100 * Defined in /system/media/camera/include/system/camera_metadata.h
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800101 */
102typedef struct camera_metadata camera_metadata_t;
103
Alex Ray9acc7402013-02-07 15:44:24 -0800104typedef struct camera_info {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800105 /**
106 * The direction that the camera faces to. It should be CAMERA_FACING_BACK
107 * or CAMERA_FACING_FRONT.
108 *
109 * Version information:
110 * Valid in all camera_module versions
111 */
112 int facing;
113
114 /**
115 * The orientation of the camera image. The value is the angle that the
116 * camera image needs to be rotated clockwise so it shows correctly on the
117 * display in its natural orientation. It should be 0, 90, 180, or 270.
118 *
119 * For example, suppose a device has a naturally tall screen. The
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800120 * back-facing camera sensor is mounted in landscape. You are looking at the
121 * screen. If the top side of the camera sensor is aligned with the right
122 * edge of the screen in natural orientation, the value should be 90. If the
123 * top side of a front-facing camera sensor is aligned with the right of the
124 * screen, the value should be 270.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800125 *
126 * Version information:
127 * Valid in all camera_module versions
128 */
129 int orientation;
130
131 /**
132 * The value of camera_device_t.common.version.
133 *
134 * Version information (based on camera_module_t.common.module_api_version):
135 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700136 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800137 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700138 * Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800139 * not read this field.
140 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800141 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800142 *
143 * Always valid
144 *
145 */
146 uint32_t device_version;
147
148 /**
149 * The camera's fixed characteristics, which include all camera metadata in
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700150 * the android.*.info.* sections. This should be a sorted metadata buffer,
151 * and may not be modified or freed by the caller. The pointer should remain
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800152 * valid for the lifetime of the camera module, and values in it may not
153 * change after it is returned by get_camera_info().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800154 *
155 * Version information (based on camera_module_t.common.module_api_version):
156 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700157 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800158 *
159 * Not valid. Extra characteristics are not available. Do not read this
160 * field.
161 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800162 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800163 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700164 * Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
165 * otherwise.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800166 *
167 */
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700168 const camera_metadata_t *static_camera_characteristics;
Alex Ray9acc7402013-02-07 15:44:24 -0800169} camera_info_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800170
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800171/**
172 * camera_device_status_t:
173 *
174 * The current status of the camera device, as provided by the HAL through the
175 * camera_module_callbacks.camera_device_status_change() call.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700176 *
177 * At module load time, the framework will assume all camera devices are in the
178 * CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke
179 * camera_module_callbacks::camera_device_status_change to inform the framework
180 * of any initially NOT_PRESENT devices.
181 *
182 * Allowed transitions:
183 * PRESENT -> NOT_PRESENT
184 * NOT_PRESENT -> ENUMERATING
185 * NOT_PRESENT -> PRESENT
186 * ENUMERATING -> PRESENT
187 * ENUMERATING -> NOT_PRESENT
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800188 */
189typedef enum camera_device_status {
190 /**
191 * The camera device is not currently connected, and opening it will return
192 * failure. Calls to get_camera_info must still succeed, and provide the
193 * same information it would if the camera were connected
194 */
195 CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
196
197 /**
198 * The camera device is connected, and opening it will succeed. The
199 * information returned by get_camera_info cannot change due to this status
200 * change. By default, the framework will assume all devices are in this
201 * state.
202 */
Igor Murashkin152b50f2013-03-18 13:30:14 -0700203 CAMERA_DEVICE_STATUS_PRESENT = 1,
204
205 /**
206 * The camera device is connected, but it is undergoing an enumeration and
207 * so opening the device will return -EBUSY. Calls to get_camera_info
208 * must still succeed, as if the camera was in the PRESENT status.
209 */
210 CAMERA_DEVICE_STATUS_ENUMERATING = 2,
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800211
212} camera_device_status_t;
213
214/**
215 * Callback functions for the camera HAL module to use to inform the framework
216 * of changes to the camera subsystem. These are called only by HAL modules
217 * implementing version CAMERA_MODULE_API_VERSION_2_1 or higher of the HAL
218 * module API interface.
219 */
220typedef struct camera_module_callbacks {
221
222 /**
223 * camera_device_status_change:
224 *
225 * Callback to the framework to indicate that the state of a specific camera
226 * device has changed. At module load time, the framework will assume all
227 * camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
228 * must call this method to inform the framework of any initially
229 * NOT_PRESENT devices.
230 *
231 * camera_module_callbacks: The instance of camera_module_callbacks_t passed
232 * to the module with set_callbacks.
233 *
234 * camera_id: The ID of the camera device that has a new status.
235 *
236 * new_status: The new status code, one of the camera_device_status_t enums,
237 * or a platform-specific status.
238 *
239 */
240 void (*camera_device_status_change)(const struct camera_module_callbacks*,
241 int camera_id,
242 int new_status);
243
244} camera_module_callbacks_t;
245
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800246typedef struct camera_module {
247 hw_module_t common;
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800248
249 /**
250 * get_number_of_cameras:
251 *
252 * Returns the number of camera devices accessible through the camera
253 * module. The camera devices are numbered 0 through N-1, where N is the
254 * value returned by this call. The name of the camera device for open() is
255 * simply the number converted to a string. That is, "0" for camera ID 0,
256 * "1" for camera ID 1.
257 *
258 * The value here must be static, and cannot change after the first call to
259 * this method
260 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800261 int (*get_number_of_cameras)(void);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800262
263 /**
264 * get_camera_info:
265 *
266 * Return the static camera information for a given camera device. This
267 * information may not change for a camera device.
268 *
269 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800270 int (*get_camera_info)(int camera_id, struct camera_info *info);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800271
272 /**
273 * set_callbacks:
274 *
275 * Provide callback function pointers to the HAL module to inform framework
276 * of asynchronous camera module events. The framework will call this
277 * function once after initial camera HAL module load, after the
278 * get_number_of_cameras() method is called for the first time, and before
279 * any other calls to the module.
280 *
281 * Version information (based on camera_module_t.common.module_api_version):
282 *
283 * CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
284 *
285 * Not provided by HAL module. Framework may not call this function.
286 *
287 * CAMERA_MODULE_API_VERSION_2_1:
288 *
289 * Valid to be called by the framework.
290 *
291 */
292 int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
293
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800294} camera_module_t;
295
296__END_DECLS
297
298#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */