The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 20 | #include <binder/IMemory.h> |
Jamie Gennis | 85cfdd0 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 21 | #include <ui/egl/android_natives.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <utils/RefBase.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 23 | #include <surfaceflinger/ISurface.h> |
James Dong | 769bb2a | 2010-10-06 18:11:23 -0700 | [diff] [blame] | 24 | #include <ui/android_native_buffer.h> |
| 25 | #include <ui/GraphicBuffer.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 26 | #include <camera/Camera.h> |
| 27 | #include <camera/CameraParameters.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 30 | |
| 31 | class Overlay; |
| 32 | |
Wu-cheng Li | 4cb04c4 | 2009-10-23 17:39:46 +0800 | [diff] [blame] | 33 | /** |
| 34 | * The size of image for display. |
| 35 | */ |
| 36 | typedef 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 43 | typedef void (*notify_callback)(int32_t msgType, |
| 44 | int32_t ext1, |
| 45 | int32_t ext2, |
| 46 | void* user); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 48 | typedef void (*data_callback)(int32_t msgType, |
| 49 | const sp<IMemory>& dataPtr, |
| 50 | void* user); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | |
James Dong | 769bb2a | 2010-10-06 18:11:23 -0700 | [diff] [blame] | 52 | #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 | */ |
| 58 | typedef 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 Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 63 | typedef void (*data_callback_timestamp)(nsecs_t timestamp, |
| 64 | int32_t msgType, |
| 65 | const sp<IMemory>& dataPtr, |
| 66 | void* user); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
| 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 Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 83 | * -# 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | * |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 88 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | * |
| 94 | * CameraService calls takePicture() to request the camera instance take a |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 95 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | */ |
| 99 | class CameraHardwareInterface : public virtual RefBase { |
| 100 | public: |
| 101 | virtual ~CameraHardwareInterface() { } |
| 102 | |
James Dong | 769bb2a | 2010-10-06 18:11:23 -0700 | [diff] [blame] | 103 | #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 Gennis | ba2bbcd | 2010-09-25 17:58:15 -0700 | [diff] [blame] | 143 | /** Set the ANativeWindow to which preview frames are sent */ |
Jamie Gennis | 85cfdd0 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 144 | virtual status_t setPreviewWindow(const sp<ANativeWindow>& buf) = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | |
| 146 | /** Return the IMemoryHeap for the raw image heap */ |
| 147 | virtual sp<IMemoryHeap> getRawHeap() const = 0; |
| 148 | |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 149 | /** 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | /** |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 156 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | */ |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 160 | |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | /** |
| 184 | * Only used if overlays are used for camera preview. |
| 185 | */ |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 186 | virtual bool useOverlay() {return false;} |
| 187 | virtual status_t setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | |
| 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 Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 200 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | * by calling releaseRecordingFrame(). |
| 203 | */ |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 204 | virtual status_t startRecording() = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | |
| 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 Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 215 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | /** |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 217 | * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | */ |
| 219 | virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0; |
| 220 | |
| 221 | /** |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 222 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | */ |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 226 | virtual status_t autoFocus() = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | |
| 228 | /** |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 229 | * 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 Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 237 | * Take a picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | */ |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 239 | virtual status_t takePicture() = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | |
| 241 | /** |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 242 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | */ |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 245 | virtual status_t cancelPicture() = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | |
| 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 Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 254 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | * 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 Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | /** |
| 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 Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 270 | /** |
| 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 | */ |
| 276 | extern "C" int HAL_getNumberOfCameras(); |
| 277 | extern "C" void HAL_getCameraInfo(int cameraId, struct CameraInfo* cameraInfo); |
Wu-cheng Li | e704438 | 2010-08-17 15:45:37 -0700 | [diff] [blame] | 278 | /* HAL should return NULL if it fails to open camera hardware. */ |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 279 | extern "C" sp<CameraHardwareInterface> HAL_openCameraHardware(int cameraId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | |
| 281 | }; // namespace android |
| 282 | |
| 283 | #endif |