blob: 561a46ddfd92ab15a257245e2586124f4c13a0fa [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
31class Overlay;
32
Wu-cheng Li4cb04c42009-10-23 17:39:46 +080033/**
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
Benny Wongda83f462009-08-12 12:01:27 -050043typedef void (*notify_callback)(int32_t msgType,
44 int32_t ext1,
45 int32_t ext2,
46 void* user);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
Benny Wongda83f462009-08-12 12:01:27 -050048typedef void (*data_callback)(int32_t msgType,
49 const sp<IMemory>& dataPtr,
50 void* user);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
James Dong769bb2a2010-10-06 18:11:23 -070052#ifdef USE_GRAPHIC_VIDEO_BUFFERS
53/**
54 * Replace data_callback_timestamp. Once we are done, this
55 * should be renamed as data_callback_timestamp, and the existing
56 * data_callback_timestamp should be deleted.
57 */
58typedef void (*videobuffer_callback_timestamp)(nsecs_t timestamp,
59 int32_t msgType,
60 const sp<android_native_buffer_t>& buf,
61 void* user);
62#endif
Benny Wongda83f462009-08-12 12:01:27 -050063typedef void (*data_callback_timestamp)(nsecs_t timestamp,
64 int32_t msgType,
65 const sp<IMemory>& dataPtr,
66 void* user);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067
68/**
69 * CameraHardwareInterface.h defines the interface to the
70 * camera hardware abstraction layer, used for setting and getting
71 * parameters, live previewing, and taking pictures.
72 *
73 * It is a referenced counted interface with RefBase as its base class.
74 * CameraService calls openCameraHardware() to retrieve a strong pointer to the
75 * instance of this interface and may be called multiple times. The
76 * following steps describe a typical sequence:
77 *
78 * -# After CameraService calls openCameraHardware(), getParameters() and
79 * setParameters() are used to initialize the camera instance.
80 * CameraService calls getPreviewHeap() to establish access to the
81 * preview heap so it can be registered with SurfaceFlinger for
82 * efficient display updating while in preview mode.
Benny Wongda83f462009-08-12 12:01:27 -050083 * -# startPreview() is called. The camera instance then periodically
84 * sends the message CAMERA_MSG_PREVIEW_FRAME (if enabled) each time
85 * a new preview frame is available. If data callback code needs to use
86 * this memory after returning, it must copy the data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 *
Benny Wongda83f462009-08-12 12:01:27 -050088 * Prior to taking a picture, CameraService calls autofocus(). When auto
89 * focusing has completed, the camera instance sends a CAMERA_MSG_FOCUS notification,
90 * which informs the application whether focusing was successful. The camera instance
91 * only sends this message once and it is up to the application to call autoFocus()
92 * again if refocusing is desired.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 *
94 * CameraService calls takePicture() to request the camera instance take a
Benny Wongda83f462009-08-12 12:01:27 -050095 * picture. At this point, if a shutter, postview, raw, and/or compressed callback
96 * is desired, the corresponding message must be enabled. As with CAMERA_MSG_PREVIEW_FRAME,
97 * 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 -080098 */
99class CameraHardwareInterface : public virtual RefBase {
100public:
101 virtual ~CameraHardwareInterface() { }
102
James Dong769bb2a2010-10-06 18:11:23 -0700103#ifdef USE_GRAPHIC_VIDEO_BUFFERS
104 /**
105 * Replace existing setCallbacks() method. Once we are done, the
106 * videobuffer_callback_timestamp parameter will be renamed to
107 * data_callback_timestamp, but its signature will be the same
108 * as videobuffer_callback_timestamp, which will be renamed
109 * to data_callback_timestamp and the exiting data_callback_timestamp
110 * will be deleted.
111 */
112 virtual void setCallbacks(notify_callback notify_cb,
113 data_callback data_cb,
114 videobuffer_callback_timestamp data_cb_timestamp,
115 void* user) = 0;
116
117 /**
118 * Replace releaseRecordingFrame(). releaseRecordingFrame() should be
119 * changed so that it has the same signature of releaseVideoBuffer(),
120 * once we are done, and releaseVideoBuffer() will be deleted.
121 */
122 virtual void releaseVideoBuffer(const sp<android_native_buffer_t>& buf) = 0;
123
124 /**
125 * This method should be called after startRecording().
126 *
127 * @param nBuffers the total number of video buffers allocated by the camera
128 * hal
129 * @param buffers an array allocated by the camera hal to hold the pointers
130 * to the individual video buffers. The video buffers and the buffers array
131 * should NOT be modified/released by camera hal until stopRecording() is
132 * called and all outstanding video buffers previously sent out via
133 * CAMERA_MSG_VIDEO_FRAME have been released via releaseVideoBuffer().
134 * Camera hal client must not release the individual buffers and the buffers
135 * array.
136 * @return no error if OK.
137 */
138 virtual status_t getVideoBufferInfo(
139 sp<android_native_buffer_t>** buffers,
140 size_t *nBuffers) = 0;
141#endif
142
Jamie Gennisba2bbcd2010-09-25 17:58:15 -0700143 /** Set the ANativeWindow to which preview frames are sent */
Jamie Gennis85cfdd02010-08-10 16:37:53 -0700144 virtual status_t setPreviewWindow(const sp<ANativeWindow>& buf) = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145
146 /** Return the IMemoryHeap for the raw image heap */
147 virtual sp<IMemoryHeap> getRawHeap() const = 0;
148
Benny Wongda83f462009-08-12 12:01:27 -0500149 /** Set the notification and data callbacks */
150 virtual void setCallbacks(notify_callback notify_cb,
151 data_callback data_cb,
152 data_callback_timestamp data_cb_timestamp,
153 void* user) = 0;
154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 /**
Benny Wongda83f462009-08-12 12:01:27 -0500156 * The following three functions all take a msgtype,
157 * which is a bitmask of the messages defined in
158 * include/ui/Camera.h
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 */
Benny Wongda83f462009-08-12 12:01:27 -0500160
161 /**
162 * Enable a message, or set of messages.
163 */
164 virtual void enableMsgType(int32_t msgType) = 0;
165
166 /**
167 * Disable a message, or a set of messages.
168 */
169 virtual void disableMsgType(int32_t msgType) = 0;
170
171 /**
172 * Query whether a message, or a set of messages, is enabled.
173 * Note that this is operates as an AND, if any of the messages
174 * queried are off, this will return false.
175 */
176 virtual bool msgTypeEnabled(int32_t msgType) = 0;
177
178 /**
179 * Start preview mode.
180 */
181 virtual status_t startPreview() = 0;
182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 /**
184 * Only used if overlays are used for camera preview.
185 */
Benny Wongda83f462009-08-12 12:01:27 -0500186 virtual bool useOverlay() {return false;}
187 virtual status_t setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188
189 /**
190 * Stop a previously started preview.
191 */
192 virtual void stopPreview() = 0;
193
194 /**
195 * Returns true if preview is enabled.
196 */
197 virtual bool previewEnabled() = 0;
198
199 /**
Benny Wongda83f462009-08-12 12:01:27 -0500200 * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME
201 * message is sent with the corresponding frame. Every record frame must be released
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 * by calling releaseRecordingFrame().
203 */
Benny Wongda83f462009-08-12 12:01:27 -0500204 virtual status_t startRecording() = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205
206 /**
207 * Stop a previously started recording.
208 */
209 virtual void stopRecording() = 0;
210
211 /**
212 * Returns true if recording is enabled.
213 */
214 virtual bool recordingEnabled() = 0;
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 /**
Benny Wongda83f462009-08-12 12:01:27 -0500217 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 */
219 virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;
220
221 /**
Benny Wongda83f462009-08-12 12:01:27 -0500222 * Start auto focus, the notification callback routine is called
223 * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus()
224 * will be called again if another auto focus is needed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 */
Benny Wongda83f462009-08-12 12:01:27 -0500226 virtual status_t autoFocus() = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227
228 /**
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800229 * Cancels auto-focus function. If the auto-focus is still in progress,
230 * this function will cancel it. Whether the auto-focus is in progress
231 * or not, this function will return the focus position to the default.
232 * If the camera does not support auto-focus, this is a no-op.
233 */
234 virtual status_t cancelAutoFocus() = 0;
235
236 /**
Benny Wongda83f462009-08-12 12:01:27 -0500237 * Take a picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 */
Benny Wongda83f462009-08-12 12:01:27 -0500239 virtual status_t takePicture() = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240
241 /**
Benny Wongda83f462009-08-12 12:01:27 -0500242 * Cancel a picture that was started with takePicture. Calling this
243 * method when no picture is being taken is a no-op.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 */
Benny Wongda83f462009-08-12 12:01:27 -0500245 virtual status_t cancelPicture() = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246
247 /** Set the camera parameters. */
248 virtual status_t setParameters(const CameraParameters& params) = 0;
249
250 /** Return the camera parameters. */
251 virtual CameraParameters getParameters() const = 0;
252
253 /**
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700254 * Send command to camera driver.
255 */
256 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
257
258 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 * Release the hardware resources owned by this object. Note that this is
260 * *not* done in the destructor.
261 */
262 virtual void release() = 0;
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 /**
265 * Dump state of the camera hardware
266 */
267 virtual status_t dump(int fd, const Vector<String16>& args) const = 0;
268};
269
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800270/**
271 * The functions need to be provided by the camera HAL.
272 *
273 * If getNumberOfCameras() returns N, the valid cameraId for getCameraInfo()
274 * and openCameraHardware() is 0 to N-1.
275 */
276extern "C" int HAL_getNumberOfCameras();
277extern "C" void HAL_getCameraInfo(int cameraId, struct CameraInfo* cameraInfo);
Wu-cheng Lie7044382010-08-17 15:45:37 -0700278/* HAL should return NULL if it fails to open camera hardware. */
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800279extern "C" sp<CameraHardwareInterface> HAL_openCameraHardware(int cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280
281}; // namespace android
282
283#endif