blob: 20d58d4fc6997167cbb30c175e08ed10d8fd6fb3 [file] [log] [blame]
Iliyan Malchev41693fa2011-04-14 23:16:54 -07001/*
2 * Copyright (C) 2010-2011 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_H
20#define ANDROID_INCLUDE_CAMERA_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
37struct camera_info {
38 /**
39 * The direction that the camera faces to. It should be CAMERA_FACING_BACK
40 * or CAMERA_FACING_FRONT.
41 */
42 int facing;
43
44 /**
45 * The orientation of the camera image. The value is the angle that the
46 * camera image needs to be rotated clockwise so it shows correctly on the
47 * display in its natural orientation. It should be 0, 90, 180, or 270.
48 *
49 * For example, suppose a device has a naturally tall screen. The
50 * back-facing camera sensor is mounted in landscape. You are looking at
51 * the screen. If the top side of the camera sensor is aligned with the
52 * right edge of the screen in natural orientation, the value should be
53 * 90. If the top side of a front-facing camera sensor is aligned with the
54 * right of the screen, the value should be 270.
55 */
56 int orientation;
57};
58
59typedef struct camera_module {
60 hw_module_t common;
61 int (*get_number_of_cameras)(void);
62 int (*get_camera_info)(int camera_id, struct camera_info *info);
63} camera_module_t;
64
Iliyan Malchev24b325e2011-06-06 16:39:06 -070065struct camera_memory;
66typedef void (*camera_release_memory)(struct camera_memory *mem);
67
Iliyan Malchev41693fa2011-04-14 23:16:54 -070068typedef struct camera_memory {
69 void *data;
70 size_t size;
71 void *handle;
Iliyan Malchev24b325e2011-06-06 16:39:06 -070072 camera_release_memory release;
Iliyan Malchev41693fa2011-04-14 23:16:54 -070073} camera_memory_t;
74
Iliyan Malchev24b325e2011-06-06 16:39:06 -070075typedef camera_memory_t* (*camera_request_memory)(int fd, size_t buf_size, unsigned int num_bufs,
76 void *user);
Iliyan Malchev41693fa2011-04-14 23:16:54 -070077
78typedef void (*camera_notify_callback)(int32_t msg_type,
79 int32_t ext1,
80 int32_t ext2,
81 void *user);
82
83typedef void (*camera_data_callback)(int32_t msg_type,
Iliyan Malchev24b325e2011-06-06 16:39:06 -070084 const camera_memory_t *data, unsigned int index,
Iliyan Malchev41693fa2011-04-14 23:16:54 -070085 void *user);
86
87typedef void (*camera_data_timestamp_callback)(int64_t timestamp,
88 int32_t msg_type,
Iliyan Malchev24b325e2011-06-06 16:39:06 -070089 const camera_memory_t *data, unsigned int index,
Iliyan Malchev41693fa2011-04-14 23:16:54 -070090 void *user);
91
92#define HAL_CAMERA_PREVIEW_WINDOW_TAG 0xcafed00d
93
94typedef struct preview_stream_ops {
95 int (*dequeue_buffer)(struct preview_stream_ops* w,
96 buffer_handle_t** buffer);
97 int (*enqueue_buffer)(struct preview_stream_ops* w,
98 buffer_handle_t* buffer);
99 int (*cancel_buffer)(struct preview_stream_ops* w,
100 buffer_handle_t* buffer);
101 int (*set_buffer_count)(struct preview_stream_ops* w, int count);
102 int (*set_buffers_geometry)(struct preview_stream_ops* pw,
103 int w, int h, int format);
104 int (*set_crop)(struct preview_stream_ops *w,
105 int left, int top, int right, int bottom);
106 int (*set_usage)(struct preview_stream_ops* w, int usage);
107 int (*set_swap_interval)(struct preview_stream_ops *w, int interval);
108
109 int (*get_min_undequeued_buffer_count)(const struct preview_stream_ops *w,
110 int *count);
111} preview_stream_ops_t;
112
113struct camera_device;
114typedef struct camera_device_ops {
115 /** Set the ANativeWindow to which preview frames are sent */
116 int (*set_preview_window)(struct camera_device *,
117 struct preview_stream_ops *window);
118
119 /** Set the notification and data callbacks */
120 void (*set_callbacks)(struct camera_device *,
121 camera_notify_callback notify_cb,
122 camera_data_callback data_cb,
123 camera_data_timestamp_callback data_cb_timestamp,
124 camera_request_memory get_memory,
125 void *user);
126
127 /**
128 * The following three functions all take a msg_type, which is a bitmask of
129 * the messages defined in include/ui/Camera.h
130 */
131
132 /**
133 * Enable a message, or set of messages.
134 */
135 void (*enable_msg_type)(struct camera_device *, int32_t msg_type);
136
137 /**
138 * Disable a message, or a set of messages.
139 *
140 * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera
141 * HAL should not rely on its client to call releaseRecordingFrame() to
142 * release video recording frames sent out by the cameral HAL before and
143 * after the disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera HAL
144 * clients must not modify/access any video recording frame after calling
145 * disableMsgType(CAMERA_MSG_VIDEO_FRAME).
146 */
147 void (*disable_msg_type)(struct camera_device *, int32_t msg_type);
148
149 /**
150 * Query whether a message, or a set of messages, is enabled. Note that
151 * this is operates as an AND, if any of the messages queried are off, this
152 * will return false.
153 */
154 int (*msg_type_enabled)(struct camera_device *, int32_t msg_type);
155
156 /**
157 * Start preview mode.
158 */
159 int (*start_preview)(struct camera_device *);
160
161 /**
162 * Stop a previously started preview.
163 */
164 void (*stop_preview)(struct camera_device *);
165
166 /**
167 * Returns true if preview is enabled.
168 */
169 int (*preview_enabled)(struct camera_device *);
170
171 /**
172 * Request the camera HAL to store meta data or real YUV data in the video
173 * buffers sent out via CAMERA_MSG_VIDEO_FRAME for a recording session. If
174 * it is not called, the default camera HAL behavior is to store real YUV
175 * data in the video buffers.
176 *
177 * This method should be called before startRecording() in order to be
178 * effective.
179 *
180 * If meta data is stored in the video buffers, it is up to the receiver of
181 * the video buffers to interpret the contents and to find the actual frame
182 * data with the help of the meta data in the buffer. How this is done is
183 * outside of the scope of this method.
184 *
185 * Some camera HALs may not support storing meta data in the video buffers,
186 * but all camera HALs should support storing real YUV data in the video
187 * buffers. If the camera HAL does not support storing the meta data in the
188 * video buffers when it is requested to do do, INVALID_OPERATION must be
189 * returned. It is very useful for the camera HAL to pass meta data rather
190 * than the actual frame data directly to the video encoder, since the
191 * amount of the uncompressed frame data can be very large if video size is
192 * large.
193 *
194 * @param enable if true to instruct the camera HAL to store
195 * meta data in the video buffers; false to instruct
196 * the camera HAL to store real YUV data in the video
197 * buffers.
198 *
199 * @return OK on success.
200 */
201 int (*store_meta_data_in_buffers)(struct camera_device *, int enable);
202
203 /**
204 * Start record mode. When a record image is available, a
205 * CAMERA_MSG_VIDEO_FRAME message is sent with the corresponding
206 * frame. Every record frame must be released by a camera HAL client via
207 * releaseRecordingFrame() before the client calls
208 * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls
209 * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
210 * responsibility to manage the life-cycle of the video recording frames,
211 * and the client must not modify/access any video recording frames.
212 */
213 int (*start_recording)(struct camera_device *);
214
215 /**
216 * Stop a previously started recording.
217 */
218 void (*stop_recording)(struct camera_device *);
219
220 /**
221 * Returns true if recording is enabled.
222 */
223 int (*recording_enabled)(struct camera_device *);
224
225 /**
226 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
227 *
228 * It is camera HAL client's responsibility to release video recording
229 * frames sent out by the camera HAL before the camera HAL receives a call
230 * to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives the call to
231 * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
232 * responsibility to manage the life-cycle of the video recording frames.
233 */
234 void (*release_recording_frame)(struct camera_device *,
235 const void *opaque);
236
237 /**
238 * Start auto focus, the notification callback routine is called with
239 * CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() will be
240 * called again if another auto focus is needed.
241 */
242 int (*auto_focus)(struct camera_device *);
243
244 /**
245 * Cancels auto-focus function. If the auto-focus is still in progress,
246 * this function will cancel it. Whether the auto-focus is in progress or
247 * not, this function will return the focus position to the default. If
248 * the camera does not support auto-focus, this is a no-op.
249 */
250 int (*cancel_auto_focus)(struct camera_device *);
251
252 /**
253 * Take a picture.
254 */
255 int (*take_picture)(struct camera_device *);
256
257 /**
258 * Cancel a picture that was started with takePicture. Calling this method
259 * when no picture is being taken is a no-op.
260 */
261 int (*cancel_picture)(struct camera_device *);
262
263 /**
264 * Set the camera parameters. This returns BAD_VALUE if any parameter is
265 * invalid or not supported.
266 */
267 int (*set_parameters)(struct camera_device *, const char *parms);
268
269 /** Return the camera parameters. */
270 char *(*get_parameters)(struct camera_device *);
271
272 /**
273 * Send command to camera driver.
274 */
275 int (*send_command)(struct camera_device *,
276 int32_t cmd, int32_t arg1, int32_t arg2);
277
278 /**
279 * Release the hardware resources owned by this object. Note that this is
280 * *not* done in the destructor.
281 */
282 void (*release)(struct camera_device *);
283
284 /**
285 * Dump state of the camera hardware
286 */
287 int (*dump)(struct camera_device *, int fd);
288} camera_device_ops_t;
289
290typedef struct camera_device {
291 hw_device_t common;
292 camera_device_ops_t *ops;
293 void *priv;
294} camera_device_t;
295
296__END_DECLS
297
298#endif /* ANDROID_INCLUDE_CAMERA_H */