blob: 22b3f7a83e069e3e7c94caa5ddb3412b753c0fa7 [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 Talvaladdc026e2012-03-27 16:15:25 -070094
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -080095// Device version 2.x is outdated; device version 3.0 is experimental
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070096#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_1_0
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080097
98/**
James Dongd0ca70d2012-03-26 16:22:35 -070099 * Defined in /system/media/camera/include/system/camera_metadata.h
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800100 */
101typedef struct camera_metadata camera_metadata_t;
102
Alex Ray9acc7402013-02-07 15:44:24 -0800103typedef struct camera_info {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800104 /**
105 * The direction that the camera faces to. It should be CAMERA_FACING_BACK
106 * or CAMERA_FACING_FRONT.
107 *
108 * Version information:
109 * Valid in all camera_module versions
110 */
111 int facing;
112
113 /**
114 * The orientation of the camera image. The value is the angle that the
115 * camera image needs to be rotated clockwise so it shows correctly on the
116 * display in its natural orientation. It should be 0, 90, 180, or 270.
117 *
118 * For example, suppose a device has a naturally tall screen. The
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800119 * back-facing camera sensor is mounted in landscape. You are looking at the
120 * screen. If the top side of the camera sensor is aligned with the right
121 * edge of the screen in natural orientation, the value should be 90. If the
122 * top side of a front-facing camera sensor is aligned with the right of the
123 * screen, the value should be 270.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800124 *
125 * Version information:
126 * Valid in all camera_module versions
127 */
128 int orientation;
129
130 /**
131 * The value of camera_device_t.common.version.
132 *
133 * Version information (based on camera_module_t.common.module_api_version):
134 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700135 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800136 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700137 * Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800138 * not read this field.
139 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800140 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800141 *
142 * Always valid
143 *
144 */
145 uint32_t device_version;
146
147 /**
148 * The camera's fixed characteristics, which include all camera metadata in
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700149 * the android.*.info.* sections. This should be a sorted metadata buffer,
150 * and may not be modified or freed by the caller. The pointer should remain
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800151 * valid for the lifetime of the camera module, and values in it may not
152 * change after it is returned by get_camera_info().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800153 *
154 * Version information (based on camera_module_t.common.module_api_version):
155 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700156 * CAMERA_MODULE_API_VERSION_1_0:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800157 *
158 * Not valid. Extra characteristics are not available. Do not read this
159 * field.
160 *
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800161 * CAMERA_MODULE_API_VERSION_2_0 or higher:
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800162 *
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700163 * Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
164 * otherwise.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800165 *
166 */
Eino-Ville Talvalab8b64392012-08-24 12:32:17 -0700167 const camera_metadata_t *static_camera_characteristics;
Alex Ray9acc7402013-02-07 15:44:24 -0800168} camera_info_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800169
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800170/**
171 * camera_device_status_t:
172 *
173 * The current status of the camera device, as provided by the HAL through the
174 * camera_module_callbacks.camera_device_status_change() call.
175 */
176typedef enum camera_device_status {
177 /**
178 * The camera device is not currently connected, and opening it will return
179 * failure. Calls to get_camera_info must still succeed, and provide the
180 * same information it would if the camera were connected
181 */
182 CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
183
184 /**
185 * The camera device is connected, and opening it will succeed. The
186 * information returned by get_camera_info cannot change due to this status
187 * change. By default, the framework will assume all devices are in this
188 * state.
189 */
190 CAMERA_DEVICE_STATUS_PRESENT = 1
191
192} camera_device_status_t;
193
194/**
195 * Callback functions for the camera HAL module to use to inform the framework
196 * of changes to the camera subsystem. These are called only by HAL modules
197 * implementing version CAMERA_MODULE_API_VERSION_2_1 or higher of the HAL
198 * module API interface.
199 */
200typedef struct camera_module_callbacks {
201
202 /**
203 * camera_device_status_change:
204 *
205 * Callback to the framework to indicate that the state of a specific camera
206 * device has changed. At module load time, the framework will assume all
207 * camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
208 * must call this method to inform the framework of any initially
209 * NOT_PRESENT devices.
210 *
211 * camera_module_callbacks: The instance of camera_module_callbacks_t passed
212 * to the module with set_callbacks.
213 *
214 * camera_id: The ID of the camera device that has a new status.
215 *
216 * new_status: The new status code, one of the camera_device_status_t enums,
217 * or a platform-specific status.
218 *
219 */
220 void (*camera_device_status_change)(const struct camera_module_callbacks*,
221 int camera_id,
222 int new_status);
223
224} camera_module_callbacks_t;
225
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800226typedef struct camera_module {
227 hw_module_t common;
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800228
229 /**
230 * get_number_of_cameras:
231 *
232 * Returns the number of camera devices accessible through the camera
233 * module. The camera devices are numbered 0 through N-1, where N is the
234 * value returned by this call. The name of the camera device for open() is
235 * simply the number converted to a string. That is, "0" for camera ID 0,
236 * "1" for camera ID 1.
237 *
238 * The value here must be static, and cannot change after the first call to
239 * this method
240 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800241 int (*get_number_of_cameras)(void);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800242
243 /**
244 * get_camera_info:
245 *
246 * Return the static camera information for a given camera device. This
247 * information may not change for a camera device.
248 *
249 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800250 int (*get_camera_info)(int camera_id, struct camera_info *info);
Eino-Ville Talvalad76f8af2013-02-13 15:29:48 -0800251
252 /**
253 * set_callbacks:
254 *
255 * Provide callback function pointers to the HAL module to inform framework
256 * of asynchronous camera module events. The framework will call this
257 * function once after initial camera HAL module load, after the
258 * get_number_of_cameras() method is called for the first time, and before
259 * any other calls to the module.
260 *
261 * Version information (based on camera_module_t.common.module_api_version):
262 *
263 * CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
264 *
265 * Not provided by HAL module. Framework may not call this function.
266 *
267 * CAMERA_MODULE_API_VERSION_2_1:
268 *
269 * Valid to be called by the framework.
270 *
271 */
272 int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
273
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800274} camera_module_t;
275
276__END_DECLS
277
278#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */