blob: 86bd8499d63be54f4fd815177564baff86e76389 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -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
Mathias Agopian07952722009-05-19 19:08:10 -070020#include <binder/IMemory.h>
Jamie Gennis85cfdd02010-08-10 16:37:53 -070021#include <ui/egl/android_natives.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022#include <utils/RefBase.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080023#include <surfaceflinger/ISurface.h>
James Dong769bb2a2010-10-06 18:11:23 -070024#include <ui/android_native_buffer.h>
25#include <ui/GraphicBuffer.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080026#include <camera/Camera.h>
27#include <camera/CameraParameters.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
29namespace android {
Mathias Agopian000479f2010-02-09 17:46:37 -080030
Wu-cheng Li4cb04c42009-10-23 17:39:46 +080031/**
32 * The size of image for display.
33 */
34typedef struct image_rect_struct
35{
36 uint32_t width; /* Image width */
37 uint32_t height; /* Image height */
38} image_rect_type;
39
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
Benny Wongda83f462009-08-12 12:01:27 -050041typedef void (*notify_callback)(int32_t msgType,
42 int32_t ext1,
43 int32_t ext2,
44 void* user);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
Benny Wongda83f462009-08-12 12:01:27 -050046typedef void (*data_callback)(int32_t msgType,
47 const sp<IMemory>& dataPtr,
48 void* user);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049
Benny Wongda83f462009-08-12 12:01:27 -050050typedef void (*data_callback_timestamp)(nsecs_t timestamp,
51 int32_t msgType,
52 const sp<IMemory>& dataPtr,
53 void* user);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
55/**
56 * CameraHardwareInterface.h defines the interface to the
57 * camera hardware abstraction layer, used for setting and getting
58 * parameters, live previewing, and taking pictures.
59 *
60 * It is a referenced counted interface with RefBase as its base class.
61 * CameraService calls openCameraHardware() to retrieve a strong pointer to the
62 * instance of this interface and may be called multiple times. The
63 * following steps describe a typical sequence:
64 *
65 * -# After CameraService calls openCameraHardware(), getParameters() and
66 * setParameters() are used to initialize the camera instance.
67 * CameraService calls getPreviewHeap() to establish access to the
68 * preview heap so it can be registered with SurfaceFlinger for
69 * efficient display updating while in preview mode.
Benny Wongda83f462009-08-12 12:01:27 -050070 * -# startPreview() is called. The camera instance then periodically
71 * sends the message CAMERA_MSG_PREVIEW_FRAME (if enabled) each time
72 * a new preview frame is available. If data callback code needs to use
73 * this memory after returning, it must copy the data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 *
Benny Wongda83f462009-08-12 12:01:27 -050075 * Prior to taking a picture, CameraService calls autofocus(). When auto
76 * focusing has completed, the camera instance sends a CAMERA_MSG_FOCUS notification,
77 * which informs the application whether focusing was successful. The camera instance
78 * only sends this message once and it is up to the application to call autoFocus()
79 * again if refocusing is desired.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 *
81 * CameraService calls takePicture() to request the camera instance take a
Benny Wongda83f462009-08-12 12:01:27 -050082 * picture. At this point, if a shutter, postview, raw, and/or compressed callback
83 * is desired, the corresponding message must be enabled. As with CAMERA_MSG_PREVIEW_FRAME,
84 * any memory provided in a data callback must be copied if it's needed after returning.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 */
86class CameraHardwareInterface : public virtual RefBase {
87public:
88 virtual ~CameraHardwareInterface() { }
89
Jamie Gennisba2bbcd2010-09-25 17:58:15 -070090 /** Set the ANativeWindow to which preview frames are sent */
Jamie Gennis85cfdd02010-08-10 16:37:53 -070091 virtual status_t setPreviewWindow(const sp<ANativeWindow>& buf) = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93 /** Return the IMemoryHeap for the raw image heap */
94 virtual sp<IMemoryHeap> getRawHeap() const = 0;
95
Benny Wongda83f462009-08-12 12:01:27 -050096 /** Set the notification and data callbacks */
97 virtual void setCallbacks(notify_callback notify_cb,
98 data_callback data_cb,
99 data_callback_timestamp data_cb_timestamp,
100 void* user) = 0;
101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 /**
Benny Wongda83f462009-08-12 12:01:27 -0500103 * The following three functions all take a msgtype,
104 * which is a bitmask of the messages defined in
105 * include/ui/Camera.h
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 */
Benny Wongda83f462009-08-12 12:01:27 -0500107
108 /**
109 * Enable a message, or set of messages.
110 */
111 virtual void enableMsgType(int32_t msgType) = 0;
112
113 /**
114 * Disable a message, or a set of messages.
James Dong74920cb2010-12-09 11:08:14 -0800115 *
116 * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera hal
117 * should not rely on its client to call releaseRecordingFrame() to release
118 * video recording frames sent out by the cameral hal before and after the
119 * disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera hal clients must not
120 * modify/access any video recording frame after calling
121 * disableMsgType(CAMERA_MSG_VIDEO_FRAME).
Benny Wongda83f462009-08-12 12:01:27 -0500122 */
123 virtual void disableMsgType(int32_t msgType) = 0;
124
125 /**
126 * Query whether a message, or a set of messages, is enabled.
127 * Note that this is operates as an AND, if any of the messages
128 * queried are off, this will return false.
129 */
130 virtual bool msgTypeEnabled(int32_t msgType) = 0;
131
132 /**
133 * Start preview mode.
134 */
135 virtual status_t startPreview() = 0;
136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 * Stop a previously started preview.
139 */
140 virtual void stopPreview() = 0;
141
142 /**
143 * Returns true if preview is enabled.
144 */
145 virtual bool previewEnabled() = 0;
146
147 /**
James Dongb0a6db22010-10-18 20:38:29 -0700148 * Retrieve the total number of available buffers from camera hal for passing
149 * video frame data in a recording session. Must be called again if a new
150 * recording session is started.
151 *
152 * This method should be called after startRecording(), since
153 * the some camera hal may choose to allocate the video buffers only after
154 * recording is started.
155 *
156 * Some camera hal may not implement this method, and 0 can be returned to
157 * indicate that this feature is not available.
158 *
159 * @return the number of video buffers that camera hal makes available.
160 * Zero (0) is returned to indicate that camera hal does not support
161 * this feature.
162 */
163 virtual int32_t getNumberOfVideoBuffers() const { return 0; }
164
165 /**
166 * Retrieve the video buffer corresponding to the given index in a
167 * recording session. Must be called again if a new recording session
168 * is started.
169 *
170 * It allows a client to retrieve all video buffers that camera hal makes
171 * available to passing video frame data by calling this method with all
172 * valid index values. The valid index value ranges from 0 to n, where
173 * n = getNumberOfVideoBuffers() - 1. With an index outside of the valid
174 * range, 0 must be returned. This method should be called after
175 * startRecording().
176 *
177 * The video buffers should NOT be modified/released by camera hal
178 * until stopRecording() is called and all outstanding video buffers
179 * previously sent out via CAMERA_MSG_VIDEO_FRAME have been released
180 * via releaseVideoBuffer().
181 *
182 * @param index an index to retrieve the corresponding video buffer.
183 *
184 * @return the video buffer corresponding to the given index.
185 */
186 virtual sp<IMemory> getVideoBuffer(int32_t index) const { return 0; }
187
188 /**
189 * Request the camera hal to store meta data or real YUV data in
190 * the video buffers send out via CAMERA_MSG_VIDEO_FRRAME for a
191 * recording session. If it is not called, the default camera
192 * hal behavior is to store real YUV data in the video buffers.
193 *
194 * This method should be called before startRecording() in order
195 * to be effective.
196 *
197 * If meta data is stored in the video buffers, it is up to the
198 * receiver of the video buffers to interpret the contents and
199 * to find the actual frame data with the help of the meta data
200 * in the buffer. How this is done is outside of the scope of
201 * this method.
202 *
203 * Some camera hal may not support storing meta data in the video
204 * buffers, but all camera hal should support storing real YUV data
205 * in the video buffers. If the camera hal does not support storing
206 * the meta data in the video buffers when it is requested to do
207 * do, INVALID_OPERATION must be returned. It is very useful for
208 * the camera hal to pass meta data rather than the actual frame
209 * data directly to the video encoder, since the amount of the
210 * uncompressed frame data can be very large if video size is large.
211 *
212 * @param enable if true to instruct the camera hal to store
213 * meta data in the video buffers; false to instruct
214 * the camera hal to store real YUV data in the video
215 * buffers.
216 *
217 * @return OK on success.
218 */
219 virtual status_t storeMetaDataInBuffers(bool enable) {
220 return enable? INVALID_OPERATION: OK;
221 }
222
223 /**
Benny Wongda83f462009-08-12 12:01:27 -0500224 * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME
225 * message is sent with the corresponding frame. Every record frame must be released
James Dong74920cb2010-12-09 11:08:14 -0800226 * by a cameral hal client via releaseRecordingFrame() before the client calls
227 * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls
228 * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is camera hal's responsibility
229 * to manage the life-cycle of the video recording frames, and the client must
230 * not modify/access any video recording frames.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 */
Benny Wongda83f462009-08-12 12:01:27 -0500232 virtual status_t startRecording() = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233
234 /**
235 * Stop a previously started recording.
236 */
237 virtual void stopRecording() = 0;
238
239 /**
240 * Returns true if recording is enabled.
241 */
242 virtual bool recordingEnabled() = 0;
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 /**
Benny Wongda83f462009-08-12 12:01:27 -0500245 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
James Dong74920cb2010-12-09 11:08:14 -0800246 *
247 * It is camera hal client's responsibility to release video recording
248 * frames sent out by the camera hal before the camera hal receives
249 * a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives
250 * the call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is camera hal's
251 * responsibility of managing the life-cycle of the video recording
252 * frames.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 */
254 virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;
255
256 /**
Benny Wongda83f462009-08-12 12:01:27 -0500257 * Start auto focus, the notification callback routine is called
258 * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus()
259 * will be called again if another auto focus is needed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 */
Benny Wongda83f462009-08-12 12:01:27 -0500261 virtual status_t autoFocus() = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262
263 /**
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800264 * Cancels auto-focus function. If the auto-focus is still in progress,
265 * this function will cancel it. Whether the auto-focus is in progress
266 * or not, this function will return the focus position to the default.
267 * If the camera does not support auto-focus, this is a no-op.
268 */
269 virtual status_t cancelAutoFocus() = 0;
270
271 /**
Benny Wongda83f462009-08-12 12:01:27 -0500272 * Take a picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 */
Benny Wongda83f462009-08-12 12:01:27 -0500274 virtual status_t takePicture() = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275
276 /**
Benny Wongda83f462009-08-12 12:01:27 -0500277 * Cancel a picture that was started with takePicture. Calling this
278 * method when no picture is being taken is a no-op.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 */
Benny Wongda83f462009-08-12 12:01:27 -0500280 virtual status_t cancelPicture() = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281
Wu-cheng Li99a3f3e2010-11-19 15:56:16 +0800282 /**
283 * Set the camera parameters. This returns BAD_VALUE if any parameter is
284 * invalid or not supported. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 virtual status_t setParameters(const CameraParameters& params) = 0;
286
287 /** Return the camera parameters. */
288 virtual CameraParameters getParameters() const = 0;
289
290 /**
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700291 * Send command to camera driver.
292 */
293 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
294
295 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 * Release the hardware resources owned by this object. Note that this is
297 * *not* done in the destructor.
298 */
299 virtual void release() = 0;
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 /**
302 * Dump state of the camera hardware
303 */
304 virtual status_t dump(int fd, const Vector<String16>& args) const = 0;
305};
306
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800307/**
308 * The functions need to be provided by the camera HAL.
309 *
310 * If getNumberOfCameras() returns N, the valid cameraId for getCameraInfo()
311 * and openCameraHardware() is 0 to N-1.
312 */
313extern "C" int HAL_getNumberOfCameras();
314extern "C" void HAL_getCameraInfo(int cameraId, struct CameraInfo* cameraInfo);
Wu-cheng Lie7044382010-08-17 15:45:37 -0700315/* HAL should return NULL if it fails to open camera hardware. */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800316extern "C" sp<CameraHardwareInterface> HAL_openCameraHardware(int cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317
318}; // namespace android
319
320#endif