blob: 0ee929e8151808435c92925e614b32158babc5a9 [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>
Ruben Brunk61cf9eb2014-01-14 15:27:58 -080027#include <system/camera_vendor_tags.h>
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080028#include <hardware/hardware.h>
29#include <hardware/gralloc.h>
30
31__BEGIN_DECLS
32
33/**
34 * The id of this module
35 */
36#define CAMERA_HARDWARE_MODULE_ID "camera"
37
38/**
39 * Module versioning information for the Camera hardware module, based on
40 * camera_module_t.common.module_api_version. The two most significant hex
41 * digits represent the major version, and the two least significant represent
42 * the minor version.
43 *
44 *******************************************************************************
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070045 * Versions: 0.X - 1.X [CAMERA_MODULE_API_VERSION_1_0]
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080046 *
47 * Camera modules that report these version numbers implement the initial
48 * camera module HAL interface. All camera devices openable through this
49 * module support only version 1 of the camera device HAL. The device_version
50 * and static_camera_characteristics fields of camera_info are not valid. Only
51 * the android.hardware.Camera API can be supported by this module and its
52 * devices.
53 *
54 *******************************************************************************
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070055 * Version: 2.0 [CAMERA_MODULE_API_VERSION_2_0]
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080056 *
57 * Camera modules that report this version number implement the second version
58 * of the camera module HAL interface. Camera devices openable through this
59 * module may support either version 1.0 or version 2.0 of the camera device
60 * HAL interface. The device_version field of camera_info is always valid; the
61 * static_camera_characteristics field of camera_info is valid if the
62 * device_version field is 2.0 or higher.
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -080063 *
64 *******************************************************************************
65 * Version: 2.1 [CAMERA_MODULE_API_VERSION_2_1]
66 *
67 * This camera module version adds support for asynchronous callbacks to the
68 * framework from the camera HAL module, which is used to notify the framework
69 * about changes to the camera module state. Modules that provide a valid
70 * set_callbacks() method must report at least this version number.
Alex Ray19b2cea2013-06-13 12:40:52 -070071 *
72 *******************************************************************************
73 * Version: 2.2 [CAMERA_MODULE_API_VERSION_2_2]
74 *
75 * This camera module version adds vendor tag support from the module, and
76 * deprecates the old vendor_tag_query_ops that were previously only
77 * accessible with a device open.
Zhijun Hebcdebf32014-06-06 15:42:17 -070078 *
79 *******************************************************************************
80 * Version: 2.3 [CAMERA_MODULE_API_VERSION_2_3]
81 *
82 * This camera module version adds open legacy camera HAL device support.
83 * Framework can use it to open the camera device as lower device HAL version
84 * HAL device if the same device can support multiple device API versions.
85 * The standard hardware module open call (common.methods->open) continues
86 * to open the camera device with the latest supported version, which is
87 * also the version listed in camera_info_t.device_version.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080088 */
89
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070090/**
91 * Predefined macros for currently-defined version numbers
92 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080093
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070094/**
95 * All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
96 * as CAMERA_MODULE_API_VERSION_1_0
97 */
98#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
99#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800100#define CAMERA_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1)
Alex Ray19b2cea2013-06-13 12:40:52 -0700101#define CAMERA_MODULE_API_VERSION_2_2 HARDWARE_MODULE_API_VERSION(2, 2)
Zhijun Hebcdebf32014-06-06 15:42:17 -0700102#define CAMERA_MODULE_API_VERSION_2_3 HARDWARE_MODULE_API_VERSION(2, 3)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700103
Zhijun Hebcdebf32014-06-06 15:42:17 -0700104#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_3
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700105
106/**
107 * All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
108 * as CAMERA_DEVICE_API_VERSION_1_0
109 */
110#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
111#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800112#define CAMERA_DEVICE_API_VERSION_2_1 HARDWARE_DEVICE_API_VERSION(2, 1)
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -0800113#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
Eino-Ville Talvala9d518562013-07-30 14:58:31 -0700114#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800115#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700116
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800117// Device version 2.x is outdated; device version 3.x is experimental
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700118#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_1_0
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800119
120/**
James Dongd0ca70d2012-03-26 16:22:35 -0700121 * Defined in /system/media/camera/include/system/camera_metadata.h
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800122 */
123typedef struct camera_metadata camera_metadata_t;
124
Alex Ray9acc7402013-02-07 15:44:24 -0800125typedef struct camera_info {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800126 /**
127 * The direction that the camera faces to. It should be CAMERA_FACING_BACK
128 * or CAMERA_FACING_FRONT.
129 *
130 * Version information:
131 * Valid in all camera_module versions
132 */
133 int facing;
134
135 /**
136 * The orientation of the camera image. The value is the angle that the
137 * camera image needs to be rotated clockwise so it shows correctly on the
138 * display in its natural orientation. It should be 0, 90, 180, or 270.
139 *
140 * For example, suppose a device has a naturally tall screen. The
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800141 * back-facing camera sensor is mounted in landscape. You are looking at the
142 * screen. If the top side of the camera sensor is aligned with the right
143 * edge of the screen in natural orientation, the value should be 90. If the
144 * top side of a front-facing camera sensor is aligned with the right of the
145 * screen, the value should be 270.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800146 *
147 * Version information:
148 * Valid in all camera_module versions
149 */
150 int orientation;
151
152 /**
153 * The value of camera_device_t.common.version.
154 *
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 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700159 * Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800160 * not read this 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 *
164 * Always valid
165 *
166 */
167 uint32_t device_version;
168
169 /**
170 * The camera's fixed characteristics, which include all camera metadata in
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700171 * the android.*.info.* sections. This should be a sorted metadata buffer,
172 * and may not be modified or freed by the caller. The pointer should remain
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800173 * valid for the lifetime of the camera module, and values in it may not
174 * change after it is returned by get_camera_info().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800175 *
176 * Version information (based on camera_module_t.common.module_api_version):
177 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700178 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800179 *
180 * Not valid. Extra characteristics are not available. Do not read this
181 * field.
182 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800183 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800184 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700185 * Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
186 * otherwise.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800187 *
188 */
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700189 const camera_metadata_t *static_camera_characteristics;
Alex Ray9acc7402013-02-07 15:44:24 -0800190} camera_info_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800191
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800192/**
193 * camera_device_status_t:
194 *
195 * The current status of the camera device, as provided by the HAL through the
196 * camera_module_callbacks.camera_device_status_change() call.
Igor Murashkin152b50f2013-03-18 13:30:14 -0700197 *
198 * At module load time, the framework will assume all camera devices are in the
199 * CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke
200 * camera_module_callbacks::camera_device_status_change to inform the framework
201 * of any initially NOT_PRESENT devices.
202 *
203 * Allowed transitions:
204 * PRESENT -> NOT_PRESENT
205 * NOT_PRESENT -> ENUMERATING
206 * NOT_PRESENT -> PRESENT
207 * ENUMERATING -> PRESENT
208 * ENUMERATING -> NOT_PRESENT
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800209 */
210typedef enum camera_device_status {
211 /**
212 * The camera device is not currently connected, and opening it will return
213 * failure. Calls to get_camera_info must still succeed, and provide the
214 * same information it would if the camera were connected
215 */
216 CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
217
218 /**
219 * The camera device is connected, and opening it will succeed. The
220 * information returned by get_camera_info cannot change due to this status
221 * change. By default, the framework will assume all devices are in this
222 * state.
223 */
Igor Murashkin152b50f2013-03-18 13:30:14 -0700224 CAMERA_DEVICE_STATUS_PRESENT = 1,
225
226 /**
227 * The camera device is connected, but it is undergoing an enumeration and
228 * so opening the device will return -EBUSY. Calls to get_camera_info
229 * must still succeed, as if the camera was in the PRESENT status.
230 */
231 CAMERA_DEVICE_STATUS_ENUMERATING = 2,
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800232
233} camera_device_status_t;
234
235/**
236 * Callback functions for the camera HAL module to use to inform the framework
237 * of changes to the camera subsystem. These are called only by HAL modules
238 * implementing version CAMERA_MODULE_API_VERSION_2_1 or higher of the HAL
239 * module API interface.
240 */
241typedef struct camera_module_callbacks {
242
243 /**
244 * camera_device_status_change:
245 *
246 * Callback to the framework to indicate that the state of a specific camera
247 * device has changed. At module load time, the framework will assume all
248 * camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
249 * must call this method to inform the framework of any initially
250 * NOT_PRESENT devices.
251 *
252 * camera_module_callbacks: The instance of camera_module_callbacks_t passed
253 * to the module with set_callbacks.
254 *
255 * camera_id: The ID of the camera device that has a new status.
256 *
257 * new_status: The new status code, one of the camera_device_status_t enums,
258 * or a platform-specific status.
259 *
260 */
261 void (*camera_device_status_change)(const struct camera_module_callbacks*,
262 int camera_id,
263 int new_status);
264
265} camera_module_callbacks_t;
266
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800267typedef struct camera_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700268 /**
269 * Common methods of the camera module. This *must* be the first member of
270 * camera_module as users of this structure will cast a hw_module_t to
271 * camera_module pointer in contexts where it's known the hw_module_t references a
272 * camera_module.
273 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800274 hw_module_t common;
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800275
276 /**
277 * get_number_of_cameras:
278 *
279 * Returns the number of camera devices accessible through the camera
280 * module. The camera devices are numbered 0 through N-1, where N is the
281 * value returned by this call. The name of the camera device for open() is
282 * simply the number converted to a string. That is, "0" for camera ID 0,
283 * "1" for camera ID 1.
284 *
285 * The value here must be static, and cannot change after the first call to
286 * this method
287 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800288 int (*get_number_of_cameras)(void);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800289
290 /**
291 * get_camera_info:
292 *
293 * Return the static camera information for a given camera device. This
294 * information may not change for a camera device.
295 *
296 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800297 int (*get_camera_info)(int camera_id, struct camera_info *info);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800298
299 /**
300 * set_callbacks:
301 *
302 * Provide callback function pointers to the HAL module to inform framework
303 * of asynchronous camera module events. The framework will call this
304 * function once after initial camera HAL module load, after the
305 * get_number_of_cameras() method is called for the first time, and before
306 * any other calls to the module.
307 *
308 * Version information (based on camera_module_t.common.module_api_version):
309 *
310 * CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
311 *
312 * Not provided by HAL module. Framework may not call this function.
313 *
314 * CAMERA_MODULE_API_VERSION_2_1:
315 *
316 * Valid to be called by the framework.
317 *
318 */
319 int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
320
Alex Ray19b2cea2013-06-13 12:40:52 -0700321 /**
322 * get_vendor_tag_ops:
323 *
324 * Get methods to query for vendor extension metadata tag information. The
325 * HAL should fill in all the vendor tag operation methods, or leave ops
326 * unchanged if no vendor tags are defined.
327 *
Ruben Brunk61cf9eb2014-01-14 15:27:58 -0800328 * The vendor_tag_ops structure used here is defined in:
329 * system/media/camera/include/system/vendor_tags.h
330 *
Alex Ray19b2cea2013-06-13 12:40:52 -0700331 * Version information (based on camera_module_t.common.module_api_version):
332 *
333 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1:
334 * Not provided by HAL module. Framework may not call this function.
335 *
336 * CAMERA_MODULE_API_VERSION_2_2:
337 * Valid to be called by the framework.
338 */
339 void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops);
340
Zhijun Hebcdebf32014-06-06 15:42:17 -0700341 /**
342 * open_legacy:
343 *
344 * Open a specific legacy camera HAL device if multiple device HAL API
345 * versions are supported by this camera HAL module. For example, if the
346 * camera module supports both CAMERA_DEVICE_API_VERSION_1_0 and
347 * CAMERA_DEVICE_API_VERSION_3_2 device API for the same camera id,
348 * framework can call this function to open the camera device as
349 * CAMERA_DEVICE_API_VERSION_1_0 device.
350 *
351 * This is an optional method. A Camera HAL module does not need to support
352 * more than one device HAL version per device, and such modules may return
353 * -ENOSYS for all calls to this method. For all older HAL device API
354 * versions that are not supported, it may return -EOPNOTSUPP. When above
355 * cases occur, The normal open() method (common.methods->open) will be
356 * used by the framework instead.
357 *
358 * Version information (based on camera_module_t.common.module_api_version):
359 *
360 * CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2:
361 * Not provided by HAL module. Framework will not call this function.
362 *
363 * CAMERA_MODULE_API_VERSION_2_3:
364 * Valid to be called by the framework.
365 *
366 * Return values:
367 *
368 * 0: On a successful open of the camera device.
369 *
370 * -ENOSYS This method is not supported.
371 *
372 * -EOPNOTSUPP: The requested HAL version is not supported by this method.
373 *
374 * -EINVAL: The input arguments are invalid, i.e. the id is invalid,
375 * and/or the module is invalid.
376 *
377 * -EBUSY: The camera device was already opened for this camera id
378 * (by using this method or common.methods->open method),
379 * regardless of the device HAL version it was opened as.
380 *
381 * -EUSERS: The maximal number of camera devices that can be
382 * opened concurrently were opened already, either by
383 * this method or common.methods->open method.
384 */
385 int (*open_legacy)(const struct hw_module_t* module, const char* id,
386 uint32_t halVersion, struct hw_device_t** device);
387
Alex Ray19b2cea2013-06-13 12:40:52 -0700388 /* reserved for future use */
Zhijun Hebcdebf32014-06-06 15:42:17 -0700389 void* reserved[7];
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800390} camera_module_t;
391
392__END_DECLS
393
394#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */