blob: 5465441c200822f71bd04275d5f4b4a56ed710a5 [file] [log] [blame]
Mathias Agopian3cf61352010-02-09 17:46:37 -08001/*
2 * Copyright (C) 2008 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#ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H
18#define ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H
19
20#include <binder/IMemory.h>
Jamie Gennis4b791682010-08-10 16:37:53 -070021#include <ui/egl/android_natives.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080022#include <utils/RefBase.h>
23#include <surfaceflinger/ISurface.h>
James Donga9424e22010-10-06 18:11:23 -070024#include <ui/android_native_buffer.h>
25#include <ui/GraphicBuffer.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080026#include <camera/Camera.h>
27#include <camera/CameraParameters.h>
28
29namespace android {
30
31class Overlay;
32
33/**
34 * The size of image for display.
35 */
36typedef struct image_rect_struct
37{
38 uint32_t width; /* Image width */
39 uint32_t height; /* Image height */
40} image_rect_type;
41
42
43typedef void (*notify_callback)(int32_t msgType,
44 int32_t ext1,
45 int32_t ext2,
46 void* user);
47
48typedef void (*data_callback)(int32_t msgType,
49 const sp<IMemory>& dataPtr,
50 void* user);
51
52typedef void (*data_callback_timestamp)(nsecs_t timestamp,
53 int32_t msgType,
54 const sp<IMemory>& dataPtr,
55 void* user);
56
57/**
58 * CameraHardwareInterface.h defines the interface to the
59 * camera hardware abstraction layer, used for setting and getting
60 * parameters, live previewing, and taking pictures.
61 *
62 * It is a referenced counted interface with RefBase as its base class.
63 * CameraService calls openCameraHardware() to retrieve a strong pointer to the
64 * instance of this interface and may be called multiple times. The
65 * following steps describe a typical sequence:
66 *
67 * -# After CameraService calls openCameraHardware(), getParameters() and
68 * setParameters() are used to initialize the camera instance.
69 * CameraService calls getPreviewHeap() to establish access to the
70 * preview heap so it can be registered with SurfaceFlinger for
71 * efficient display updating while in preview mode.
72 * -# startPreview() is called. The camera instance then periodically
73 * sends the message CAMERA_MSG_PREVIEW_FRAME (if enabled) each time
74 * a new preview frame is available. If data callback code needs to use
75 * this memory after returning, it must copy the data.
76 *
77 * Prior to taking a picture, CameraService calls autofocus(). When auto
78 * focusing has completed, the camera instance sends a CAMERA_MSG_FOCUS notification,
79 * which informs the application whether focusing was successful. The camera instance
80 * only sends this message once and it is up to the application to call autoFocus()
81 * again if refocusing is desired.
82 *
83 * CameraService calls takePicture() to request the camera instance take a
84 * picture. At this point, if a shutter, postview, raw, and/or compressed callback
85 * is desired, the corresponding message must be enabled. As with CAMERA_MSG_PREVIEW_FRAME,
86 * any memory provided in a data callback must be copied if it's needed after returning.
87 */
88class CameraHardwareInterface : public virtual RefBase {
89public:
90 virtual ~CameraHardwareInterface() { }
91
Jamie Gennisa77e0592010-09-25 17:58:15 -070092 /** Set the ANativeWindow to which preview frames are sent */
Jamie Gennis4b791682010-08-10 16:37:53 -070093 virtual status_t setPreviewWindow(const sp<ANativeWindow>& buf) = 0;
Mathias Agopian3cf61352010-02-09 17:46:37 -080094
95 /** Return the IMemoryHeap for the raw image heap */
96 virtual sp<IMemoryHeap> getRawHeap() const = 0;
97
98 /** Set the notification and data callbacks */
99 virtual void setCallbacks(notify_callback notify_cb,
100 data_callback data_cb,
101 data_callback_timestamp data_cb_timestamp,
102 void* user) = 0;
103
104 /**
105 * The following three functions all take a msgtype,
106 * which is a bitmask of the messages defined in
107 * include/ui/Camera.h
108 */
109
110 /**
111 * Enable a message, or set of messages.
112 */
113 virtual void enableMsgType(int32_t msgType) = 0;
114
115 /**
116 * Disable a message, or a set of messages.
117 */
118 virtual void disableMsgType(int32_t msgType) = 0;
119
120 /**
121 * Query whether a message, or a set of messages, is enabled.
122 * Note that this is operates as an AND, if any of the messages
123 * queried are off, this will return false.
124 */
125 virtual bool msgTypeEnabled(int32_t msgType) = 0;
126
127 /**
128 * Start preview mode.
129 */
130 virtual status_t startPreview() = 0;
131
132 /**
133 * Only used if overlays are used for camera preview.
134 */
135 virtual bool useOverlay() {return false;}
136 virtual status_t setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;}
137
138 /**
139 * Stop a previously started preview.
140 */
141 virtual void stopPreview() = 0;
142
143 /**
144 * Returns true if preview is enabled.
145 */
146 virtual bool previewEnabled() = 0;
147
148 /**
James Dong8be92d52010-10-18 20:38:29 -0700149 * Retrieve the total number of available buffers from camera hal for passing
150 * video frame data in a recording session. Must be called again if a new
151 * recording session is started.
152 *
153 * This method should be called after startRecording(), since
154 * the some camera hal may choose to allocate the video buffers only after
155 * recording is started.
156 *
157 * Some camera hal may not implement this method, and 0 can be returned to
158 * indicate that this feature is not available.
159 *
160 * @return the number of video buffers that camera hal makes available.
161 * Zero (0) is returned to indicate that camera hal does not support
162 * this feature.
163 */
164 virtual int32_t getNumberOfVideoBuffers() const { return 0; }
165
166 /**
167 * Retrieve the video buffer corresponding to the given index in a
168 * recording session. Must be called again if a new recording session
169 * is started.
170 *
171 * It allows a client to retrieve all video buffers that camera hal makes
172 * available to passing video frame data by calling this method with all
173 * valid index values. The valid index value ranges from 0 to n, where
174 * n = getNumberOfVideoBuffers() - 1. With an index outside of the valid
175 * range, 0 must be returned. This method should be called after
176 * startRecording().
177 *
178 * The video buffers should NOT be modified/released by camera hal
179 * until stopRecording() is called and all outstanding video buffers
180 * previously sent out via CAMERA_MSG_VIDEO_FRAME have been released
181 * via releaseVideoBuffer().
182 *
183 * @param index an index to retrieve the corresponding video buffer.
184 *
185 * @return the video buffer corresponding to the given index.
186 */
187 virtual sp<IMemory> getVideoBuffer(int32_t index) const { return 0; }
188
189 /**
190 * Request the camera hal to store meta data or real YUV data in
191 * the video buffers send out via CAMERA_MSG_VIDEO_FRRAME for a
192 * recording session. If it is not called, the default camera
193 * hal behavior is to store real YUV data in the video buffers.
194 *
195 * This method should be called before startRecording() in order
196 * to be effective.
197 *
198 * If meta data is stored in the video buffers, it is up to the
199 * receiver of the video buffers to interpret the contents and
200 * to find the actual frame data with the help of the meta data
201 * in the buffer. How this is done is outside of the scope of
202 * this method.
203 *
204 * Some camera hal may not support storing meta data in the video
205 * buffers, but all camera hal should support storing real YUV data
206 * in the video buffers. If the camera hal does not support storing
207 * the meta data in the video buffers when it is requested to do
208 * do, INVALID_OPERATION must be returned. It is very useful for
209 * the camera hal to pass meta data rather than the actual frame
210 * data directly to the video encoder, since the amount of the
211 * uncompressed frame data can be very large if video size is large.
212 *
213 * @param enable if true to instruct the camera hal to store
214 * meta data in the video buffers; false to instruct
215 * the camera hal to store real YUV data in the video
216 * buffers.
217 *
218 * @return OK on success.
219 */
220 virtual status_t storeMetaDataInBuffers(bool enable) {
221 return enable? INVALID_OPERATION: OK;
222 }
223
224 /**
Mathias Agopian3cf61352010-02-09 17:46:37 -0800225 * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME
226 * message is sent with the corresponding frame. Every record frame must be released
227 * by calling releaseRecordingFrame().
228 */
229 virtual status_t startRecording() = 0;
230
231 /**
232 * Stop a previously started recording.
233 */
234 virtual void stopRecording() = 0;
235
236 /**
237 * Returns true if recording is enabled.
238 */
239 virtual bool recordingEnabled() = 0;
240
241 /**
242 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
243 */
244 virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;
245
246 /**
247 * Start auto focus, the notification callback routine is called
248 * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus()
249 * will be called again if another auto focus is needed.
250 */
251 virtual status_t autoFocus() = 0;
252
253 /**
254 * Cancels auto-focus function. If the auto-focus is still in progress,
255 * this function will cancel it. Whether the auto-focus is in progress
256 * or not, this function will return the focus position to the default.
257 * If the camera does not support auto-focus, this is a no-op.
258 */
259 virtual status_t cancelAutoFocus() = 0;
260
261 /**
262 * Take a picture.
263 */
264 virtual status_t takePicture() = 0;
265
266 /**
267 * Cancel a picture that was started with takePicture. Calling this
268 * method when no picture is being taken is a no-op.
269 */
270 virtual status_t cancelPicture() = 0;
271
272 /** Set the camera parameters. */
273 virtual status_t setParameters(const CameraParameters& params) = 0;
274
275 /** Return the camera parameters. */
276 virtual CameraParameters getParameters() const = 0;
277
278 /**
279 * Send command to camera driver.
280 */
281 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
282
283 /**
284 * Release the hardware resources owned by this object. Note that this is
285 * *not* done in the destructor.
286 */
287 virtual void release() = 0;
288
289 /**
290 * Dump state of the camera hardware
291 */
292 virtual status_t dump(int fd, const Vector<String16>& args) const = 0;
293};
294
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800295/**
296 * The functions need to be provided by the camera HAL.
297 *
298 * If getNumberOfCameras() returns N, the valid cameraId for getCameraInfo()
299 * and openCameraHardware() is 0 to N-1.
300 */
301extern "C" int HAL_getNumberOfCameras();
302extern "C" void HAL_getCameraInfo(int cameraId, struct CameraInfo* cameraInfo);
Wu-cheng Lib7a67942010-08-17 15:45:37 -0700303/* HAL should return NULL if it fails to open camera hardware. */
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800304extern "C" sp<CameraHardwareInterface> HAL_openCameraHardware(int cameraId);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800305
306}; // namespace android
307
308#endif