blob: 3f34120dfff5f4500b64058fb49fcfa1eb0ea67f [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
Mathias Agopian3cf61352010-02-09 17:46:37 -080031typedef void (*notify_callback)(int32_t msgType,
32 int32_t ext1,
33 int32_t ext2,
34 void* user);
35
36typedef void (*data_callback)(int32_t msgType,
37 const sp<IMemory>& dataPtr,
38 void* user);
39
40typedef void (*data_callback_timestamp)(nsecs_t timestamp,
41 int32_t msgType,
42 const sp<IMemory>& dataPtr,
43 void* user);
44
45/**
46 * CameraHardwareInterface.h defines the interface to the
47 * camera hardware abstraction layer, used for setting and getting
48 * parameters, live previewing, and taking pictures.
49 *
50 * It is a referenced counted interface with RefBase as its base class.
51 * CameraService calls openCameraHardware() to retrieve a strong pointer to the
52 * instance of this interface and may be called multiple times. The
53 * following steps describe a typical sequence:
54 *
55 * -# After CameraService calls openCameraHardware(), getParameters() and
56 * setParameters() are used to initialize the camera instance.
57 * CameraService calls getPreviewHeap() to establish access to the
58 * preview heap so it can be registered with SurfaceFlinger for
59 * efficient display updating while in preview mode.
60 * -# startPreview() is called. The camera instance then periodically
61 * sends the message CAMERA_MSG_PREVIEW_FRAME (if enabled) each time
62 * a new preview frame is available. If data callback code needs to use
63 * this memory after returning, it must copy the data.
64 *
65 * Prior to taking a picture, CameraService calls autofocus(). When auto
66 * focusing has completed, the camera instance sends a CAMERA_MSG_FOCUS notification,
67 * which informs the application whether focusing was successful. The camera instance
68 * only sends this message once and it is up to the application to call autoFocus()
69 * again if refocusing is desired.
70 *
71 * CameraService calls takePicture() to request the camera instance take a
72 * picture. At this point, if a shutter, postview, raw, and/or compressed callback
73 * is desired, the corresponding message must be enabled. As with CAMERA_MSG_PREVIEW_FRAME,
74 * any memory provided in a data callback must be copied if it's needed after returning.
75 */
76class CameraHardwareInterface : public virtual RefBase {
77public:
78 virtual ~CameraHardwareInterface() { }
79
Jamie Gennisa77e0592010-09-25 17:58:15 -070080 /** Set the ANativeWindow to which preview frames are sent */
Jamie Gennis4b791682010-08-10 16:37:53 -070081 virtual status_t setPreviewWindow(const sp<ANativeWindow>& buf) = 0;
Mathias Agopian3cf61352010-02-09 17:46:37 -080082
Mathias Agopian3cf61352010-02-09 17:46:37 -080083 /** Set the notification and data callbacks */
84 virtual void setCallbacks(notify_callback notify_cb,
85 data_callback data_cb,
86 data_callback_timestamp data_cb_timestamp,
87 void* user) = 0;
88
89 /**
90 * The following three functions all take a msgtype,
91 * which is a bitmask of the messages defined in
92 * include/ui/Camera.h
93 */
94
95 /**
96 * Enable a message, or set of messages.
97 */
98 virtual void enableMsgType(int32_t msgType) = 0;
99
100 /**
101 * Disable a message, or a set of messages.
James Dong986ef2a2010-12-09 11:08:14 -0800102 *
103 * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera hal
104 * should not rely on its client to call releaseRecordingFrame() to release
105 * video recording frames sent out by the cameral hal before and after the
106 * disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera hal clients must not
107 * modify/access any video recording frame after calling
108 * disableMsgType(CAMERA_MSG_VIDEO_FRAME).
Mathias Agopian3cf61352010-02-09 17:46:37 -0800109 */
110 virtual void disableMsgType(int32_t msgType) = 0;
111
112 /**
113 * Query whether a message, or a set of messages, is enabled.
114 * Note that this is operates as an AND, if any of the messages
115 * queried are off, this will return false.
116 */
117 virtual bool msgTypeEnabled(int32_t msgType) = 0;
118
119 /**
120 * Start preview mode.
121 */
122 virtual status_t startPreview() = 0;
123
124 /**
Mathias Agopian3cf61352010-02-09 17:46:37 -0800125 * Stop a previously started preview.
126 */
127 virtual void stopPreview() = 0;
128
129 /**
130 * Returns true if preview is enabled.
131 */
132 virtual bool previewEnabled() = 0;
133
134 /**
James Dong8be92d52010-10-18 20:38:29 -0700135 * Request the camera hal to store meta data or real YUV data in
136 * the video buffers send out via CAMERA_MSG_VIDEO_FRRAME for a
137 * recording session. If it is not called, the default camera
138 * hal behavior is to store real YUV data in the video buffers.
139 *
140 * This method should be called before startRecording() in order
141 * to be effective.
142 *
143 * If meta data is stored in the video buffers, it is up to the
144 * receiver of the video buffers to interpret the contents and
145 * to find the actual frame data with the help of the meta data
146 * in the buffer. How this is done is outside of the scope of
147 * this method.
148 *
149 * Some camera hal may not support storing meta data in the video
150 * buffers, but all camera hal should support storing real YUV data
151 * in the video buffers. If the camera hal does not support storing
152 * the meta data in the video buffers when it is requested to do
153 * do, INVALID_OPERATION must be returned. It is very useful for
154 * the camera hal to pass meta data rather than the actual frame
155 * data directly to the video encoder, since the amount of the
156 * uncompressed frame data can be very large if video size is large.
157 *
158 * @param enable if true to instruct the camera hal to store
159 * meta data in the video buffers; false to instruct
160 * the camera hal to store real YUV data in the video
161 * buffers.
162 *
163 * @return OK on success.
164 */
165 virtual status_t storeMetaDataInBuffers(bool enable) {
166 return enable? INVALID_OPERATION: OK;
167 }
168
169 /**
Mathias Agopian3cf61352010-02-09 17:46:37 -0800170 * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME
171 * message is sent with the corresponding frame. Every record frame must be released
James Dong986ef2a2010-12-09 11:08:14 -0800172 * by a cameral hal client via releaseRecordingFrame() before the client calls
173 * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls
174 * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is camera hal's responsibility
175 * to manage the life-cycle of the video recording frames, and the client must
176 * not modify/access any video recording frames.
Mathias Agopian3cf61352010-02-09 17:46:37 -0800177 */
178 virtual status_t startRecording() = 0;
179
180 /**
181 * Stop a previously started recording.
182 */
183 virtual void stopRecording() = 0;
184
185 /**
186 * Returns true if recording is enabled.
187 */
188 virtual bool recordingEnabled() = 0;
189
190 /**
191 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
James Dong986ef2a2010-12-09 11:08:14 -0800192 *
193 * It is camera hal client's responsibility to release video recording
194 * frames sent out by the camera hal before the camera hal receives
195 * a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives
196 * the call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is camera hal's
197 * responsibility of managing the life-cycle of the video recording
198 * frames.
Mathias Agopian3cf61352010-02-09 17:46:37 -0800199 */
200 virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;
201
202 /**
203 * Start auto focus, the notification callback routine is called
204 * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus()
205 * will be called again if another auto focus is needed.
206 */
207 virtual status_t autoFocus() = 0;
208
209 /**
210 * Cancels auto-focus function. If the auto-focus is still in progress,
211 * this function will cancel it. Whether the auto-focus is in progress
212 * or not, this function will return the focus position to the default.
213 * If the camera does not support auto-focus, this is a no-op.
214 */
215 virtual status_t cancelAutoFocus() = 0;
216
217 /**
218 * Take a picture.
219 */
220 virtual status_t takePicture() = 0;
221
222 /**
223 * Cancel a picture that was started with takePicture. Calling this
224 * method when no picture is being taken is a no-op.
225 */
226 virtual status_t cancelPicture() = 0;
227
Wu-cheng Lic2c88682010-11-19 15:56:16 +0800228 /**
229 * Set the camera parameters. This returns BAD_VALUE if any parameter is
230 * invalid or not supported. */
Mathias Agopian3cf61352010-02-09 17:46:37 -0800231 virtual status_t setParameters(const CameraParameters& params) = 0;
232
233 /** Return the camera parameters. */
234 virtual CameraParameters getParameters() const = 0;
235
236 /**
237 * Send command to camera driver.
238 */
239 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
240
241 /**
242 * Release the hardware resources owned by this object. Note that this is
243 * *not* done in the destructor.
244 */
245 virtual void release() = 0;
246
247 /**
248 * Dump state of the camera hardware
249 */
250 virtual status_t dump(int fd, const Vector<String16>& args) const = 0;
251};
252
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800253/**
254 * The functions need to be provided by the camera HAL.
255 *
256 * If getNumberOfCameras() returns N, the valid cameraId for getCameraInfo()
257 * and openCameraHardware() is 0 to N-1.
258 */
259extern "C" int HAL_getNumberOfCameras();
260extern "C" void HAL_getCameraInfo(int cameraId, struct CameraInfo* cameraInfo);
Wu-cheng Lib7a67942010-08-17 15:45:37 -0700261/* HAL should return NULL if it fails to open camera hardware. */
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800262extern "C" sp<CameraHardwareInterface> HAL_openCameraHardware(int cameraId);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800263
264}; // namespace android
265
266#endif