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