blob: 3530f8d024113b79b28c676ebed1f0de6364a3a6 [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
Iliyan Malchev41693fa2011-04-14 23:16:54 -070017#ifndef ANDROID_INCLUDE_CAMERA_H
18#define ANDROID_INCLUDE_CAMERA_H
19
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080020#include "camera_common.h"
Iliyan Malchev41693fa2011-04-14 23:16:54 -070021
22/**
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080023 * Camera device HAL, initial version [ HARDWARE_DEVICE_API_VERSION(1,0) ]
24 *
25 * Supports the android.hardware.Camera API.
26 *
27 * Camera devices that support this version of the HAL must return a value in
28 * the range HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF) in
29 * camera_device_t.common.version.
30 *
31 * Camera modules that implement version 2.0 or higher of camera_module_t must
32 * also return the value of camera_device_t.common.version in
33 * camera_info_t.device_version.
34 *
35 * See camera_common.h for more details.
Iliyan Malchev41693fa2011-04-14 23:16:54 -070036 */
Iliyan Malchev41693fa2011-04-14 23:16:54 -070037
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080038__BEGIN_DECLS
Iliyan Malchev41693fa2011-04-14 23:16:54 -070039
Iliyan Malchev24b325e2011-06-06 16:39:06 -070040struct camera_memory;
41typedef void (*camera_release_memory)(struct camera_memory *mem);
42
Iliyan Malchev41693fa2011-04-14 23:16:54 -070043typedef struct camera_memory {
44 void *data;
45 size_t size;
46 void *handle;
Iliyan Malchev24b325e2011-06-06 16:39:06 -070047 camera_release_memory release;
Iliyan Malchev41693fa2011-04-14 23:16:54 -070048} camera_memory_t;
49
Iliyan Malchev24b325e2011-06-06 16:39:06 -070050typedef camera_memory_t* (*camera_request_memory)(int fd, size_t buf_size, unsigned int num_bufs,
51 void *user);
Iliyan Malchev41693fa2011-04-14 23:16:54 -070052
53typedef void (*camera_notify_callback)(int32_t msg_type,
54 int32_t ext1,
55 int32_t ext2,
56 void *user);
57
58typedef void (*camera_data_callback)(int32_t msg_type,
Iliyan Malchev24b325e2011-06-06 16:39:06 -070059 const camera_memory_t *data, unsigned int index,
Wu-cheng Li37ea6f72011-07-26 07:39:41 +080060 camera_frame_metadata_t *metadata, void *user);
Iliyan Malchev41693fa2011-04-14 23:16:54 -070061
62typedef void (*camera_data_timestamp_callback)(int64_t timestamp,
63 int32_t msg_type,
Iliyan Malchev24b325e2011-06-06 16:39:06 -070064 const camera_memory_t *data, unsigned int index,
Iliyan Malchev41693fa2011-04-14 23:16:54 -070065 void *user);
66
67#define HAL_CAMERA_PREVIEW_WINDOW_TAG 0xcafed00d
68
69typedef struct preview_stream_ops {
70 int (*dequeue_buffer)(struct preview_stream_ops* w,
Iliyan Malchev4deb1882011-06-10 16:06:52 -070071 buffer_handle_t** buffer, int *stride);
Iliyan Malchev41693fa2011-04-14 23:16:54 -070072 int (*enqueue_buffer)(struct preview_stream_ops* w,
73 buffer_handle_t* buffer);
74 int (*cancel_buffer)(struct preview_stream_ops* w,
75 buffer_handle_t* buffer);
76 int (*set_buffer_count)(struct preview_stream_ops* w, int count);
77 int (*set_buffers_geometry)(struct preview_stream_ops* pw,
78 int w, int h, int format);
79 int (*set_crop)(struct preview_stream_ops *w,
80 int left, int top, int right, int bottom);
81 int (*set_usage)(struct preview_stream_ops* w, int usage);
82 int (*set_swap_interval)(struct preview_stream_ops *w, int interval);
Iliyan Malchev41693fa2011-04-14 23:16:54 -070083 int (*get_min_undequeued_buffer_count)(const struct preview_stream_ops *w,
84 int *count);
Sundar Ramanac0e0672011-06-17 09:14:46 -050085 int (*lock_buffer)(struct preview_stream_ops* w,
86 buffer_handle_t* buffer);
Eino-Ville Talvala7c50e9b2011-07-26 14:08:21 -070087 // Timestamps are measured in nanoseconds, and must be comparable
88 // and monotonically increasing between two frames in the same
89 // preview stream. They do not need to be comparable between
90 // consecutive or parallel preview streams, cameras, or app runs.
91 int (*set_timestamp)(struct preview_stream_ops *w, int64_t timestamp);
Iliyan Malchev41693fa2011-04-14 23:16:54 -070092} preview_stream_ops_t;
93
94struct camera_device;
95typedef struct camera_device_ops {
96 /** Set the ANativeWindow to which preview frames are sent */
97 int (*set_preview_window)(struct camera_device *,
98 struct preview_stream_ops *window);
99
100 /** Set the notification and data callbacks */
101 void (*set_callbacks)(struct camera_device *,
102 camera_notify_callback notify_cb,
103 camera_data_callback data_cb,
104 camera_data_timestamp_callback data_cb_timestamp,
105 camera_request_memory get_memory,
106 void *user);
107
108 /**
109 * The following three functions all take a msg_type, which is a bitmask of
110 * the messages defined in include/ui/Camera.h
111 */
112
113 /**
114 * Enable a message, or set of messages.
115 */
116 void (*enable_msg_type)(struct camera_device *, int32_t msg_type);
117
118 /**
119 * Disable a message, or a set of messages.
120 *
121 * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera
122 * HAL should not rely on its client to call releaseRecordingFrame() to
123 * release video recording frames sent out by the cameral HAL before and
124 * after the disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera HAL
125 * clients must not modify/access any video recording frame after calling
126 * disableMsgType(CAMERA_MSG_VIDEO_FRAME).
127 */
128 void (*disable_msg_type)(struct camera_device *, int32_t msg_type);
129
130 /**
131 * Query whether a message, or a set of messages, is enabled. Note that
132 * this is operates as an AND, if any of the messages queried are off, this
133 * will return false.
134 */
135 int (*msg_type_enabled)(struct camera_device *, int32_t msg_type);
136
137 /**
138 * Start preview mode.
139 */
140 int (*start_preview)(struct camera_device *);
141
142 /**
143 * Stop a previously started preview.
144 */
145 void (*stop_preview)(struct camera_device *);
146
147 /**
148 * Returns true if preview is enabled.
149 */
150 int (*preview_enabled)(struct camera_device *);
151
152 /**
153 * Request the camera HAL to store meta data or real YUV data in the video
154 * buffers sent out via CAMERA_MSG_VIDEO_FRAME for a recording session. If
155 * it is not called, the default camera HAL behavior is to store real YUV
156 * data in the video buffers.
157 *
158 * This method should be called before startRecording() in order to be
159 * effective.
160 *
161 * If meta data is stored in the video buffers, it is up to the receiver of
162 * the video buffers to interpret the contents and to find the actual frame
163 * data with the help of the meta data in the buffer. How this is done is
164 * outside of the scope of this method.
165 *
166 * Some camera HALs may not support storing meta data in the video buffers,
167 * but all camera HALs should support storing real YUV data in the video
168 * buffers. If the camera HAL does not support storing the meta data in the
169 * video buffers when it is requested to do do, INVALID_OPERATION must be
170 * returned. It is very useful for the camera HAL to pass meta data rather
171 * than the actual frame data directly to the video encoder, since the
172 * amount of the uncompressed frame data can be very large if video size is
173 * large.
174 *
175 * @param enable if true to instruct the camera HAL to store
176 * meta data in the video buffers; false to instruct
177 * the camera HAL to store real YUV data in the video
178 * buffers.
179 *
180 * @return OK on success.
181 */
182 int (*store_meta_data_in_buffers)(struct camera_device *, int enable);
183
184 /**
185 * Start record mode. When a record image is available, a
186 * CAMERA_MSG_VIDEO_FRAME message is sent with the corresponding
187 * frame. Every record frame must be released by a camera HAL client via
188 * releaseRecordingFrame() before the client calls
189 * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls
190 * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
191 * responsibility to manage the life-cycle of the video recording frames,
192 * and the client must not modify/access any video recording frames.
193 */
194 int (*start_recording)(struct camera_device *);
195
196 /**
197 * Stop a previously started recording.
198 */
199 void (*stop_recording)(struct camera_device *);
200
201 /**
202 * Returns true if recording is enabled.
203 */
204 int (*recording_enabled)(struct camera_device *);
205
206 /**
207 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
208 *
209 * It is camera HAL client's responsibility to release video recording
210 * frames sent out by the camera HAL before the camera HAL receives a call
211 * to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives the call to
212 * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
213 * responsibility to manage the life-cycle of the video recording frames.
214 */
215 void (*release_recording_frame)(struct camera_device *,
216 const void *opaque);
217
218 /**
219 * Start auto focus, the notification callback routine is called with
220 * CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() will be
221 * called again if another auto focus is needed.
222 */
223 int (*auto_focus)(struct camera_device *);
224
225 /**
226 * Cancels auto-focus function. If the auto-focus is still in progress,
227 * this function will cancel it. Whether the auto-focus is in progress or
228 * not, this function will return the focus position to the default. If
229 * the camera does not support auto-focus, this is a no-op.
230 */
231 int (*cancel_auto_focus)(struct camera_device *);
232
233 /**
234 * Take a picture.
235 */
236 int (*take_picture)(struct camera_device *);
237
238 /**
239 * Cancel a picture that was started with takePicture. Calling this method
240 * when no picture is being taken is a no-op.
241 */
242 int (*cancel_picture)(struct camera_device *);
243
244 /**
245 * Set the camera parameters. This returns BAD_VALUE if any parameter is
246 * invalid or not supported.
247 */
248 int (*set_parameters)(struct camera_device *, const char *parms);
249
Iliyan Malchev22800032011-07-26 15:47:56 -0700250 /** Retrieve the camera parameters. The buffer returned by the camera HAL
251 must be returned back to it with put_parameters, if put_parameters
252 is not NULL.
253 */
Iliyan Malchev41693fa2011-04-14 23:16:54 -0700254 char *(*get_parameters)(struct camera_device *);
255
Iliyan Malchev22800032011-07-26 15:47:56 -0700256 /** The camera HAL uses its own memory to pass us the parameters when we
257 call get_parameters. Use this function to return the memory back to
258 the camera HAL, if put_parameters is not NULL. If put_parameters
259 is NULL, then you have to use free() to release the memory.
260 */
261 void (*put_parameters)(struct camera_device *, char *);
262
Iliyan Malchev41693fa2011-04-14 23:16:54 -0700263 /**
264 * Send command to camera driver.
265 */
266 int (*send_command)(struct camera_device *,
267 int32_t cmd, int32_t arg1, int32_t arg2);
268
269 /**
270 * Release the hardware resources owned by this object. Note that this is
271 * *not* done in the destructor.
272 */
273 void (*release)(struct camera_device *);
274
275 /**
276 * Dump state of the camera hardware
277 */
278 int (*dump)(struct camera_device *, int fd);
279} camera_device_ops_t;
280
281typedef struct camera_device {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800282 /**
283 * camera_device.common.version must be in the range
284 * HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF). (1,0) is recommended.
285 */
Iliyan Malchev41693fa2011-04-14 23:16:54 -0700286 hw_device_t common;
287 camera_device_ops_t *ops;
288 void *priv;
289} camera_device_t;
290
291__END_DECLS
292
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800293#endif /* #ifdef ANDROID_INCLUDE_CAMERA_H */