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> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <utils/RefBase.h> |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 22 | #include <ui/ISurface.h> |
| 23 | #include <ui/Camera.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <ui/CameraParameters.h> |
| 25 | #include <ui/Overlay.h> |
| 26 | |
| 27 | namespace android { |
Wu-cheng Li | 4cb04c4 | 2009-10-23 17:39:46 +0800 | [diff] [blame^] | 28 | /** |
| 29 | * The size of image for display. |
| 30 | */ |
| 31 | typedef struct image_rect_struct |
| 32 | { |
| 33 | uint32_t width; /* Image width */ |
| 34 | uint32_t height; /* Image height */ |
| 35 | } image_rect_type; |
| 36 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 38 | typedef void (*notify_callback)(int32_t msgType, |
| 39 | int32_t ext1, |
| 40 | int32_t ext2, |
| 41 | void* user); |
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 (*data_callback)(int32_t msgType, |
| 44 | const sp<IMemory>& dataPtr, |
| 45 | void* user); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 47 | typedef void (*data_callback_timestamp)(nsecs_t timestamp, |
| 48 | 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 | |
| 52 | /** |
| 53 | * CameraHardwareInterface.h defines the interface to the |
| 54 | * camera hardware abstraction layer, used for setting and getting |
| 55 | * parameters, live previewing, and taking pictures. |
| 56 | * |
| 57 | * It is a referenced counted interface with RefBase as its base class. |
| 58 | * CameraService calls openCameraHardware() to retrieve a strong pointer to the |
| 59 | * instance of this interface and may be called multiple times. The |
| 60 | * following steps describe a typical sequence: |
| 61 | * |
| 62 | * -# After CameraService calls openCameraHardware(), getParameters() and |
| 63 | * setParameters() are used to initialize the camera instance. |
| 64 | * CameraService calls getPreviewHeap() to establish access to the |
| 65 | * preview heap so it can be registered with SurfaceFlinger for |
| 66 | * efficient display updating while in preview mode. |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 67 | * -# startPreview() is called. The camera instance then periodically |
| 68 | * sends the message CAMERA_MSG_PREVIEW_FRAME (if enabled) each time |
| 69 | * a new preview frame is available. If data callback code needs to use |
| 70 | * this memory after returning, it must copy the data. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | * |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 72 | * Prior to taking a picture, CameraService calls autofocus(). When auto |
| 73 | * focusing has completed, the camera instance sends a CAMERA_MSG_FOCUS notification, |
| 74 | * which informs the application whether focusing was successful. The camera instance |
| 75 | * only sends this message once and it is up to the application to call autoFocus() |
| 76 | * again if refocusing is desired. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | * |
| 78 | * CameraService calls takePicture() to request the camera instance take a |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 79 | * picture. At this point, if a shutter, postview, raw, and/or compressed callback |
| 80 | * is desired, the corresponding message must be enabled. As with CAMERA_MSG_PREVIEW_FRAME, |
| 81 | * 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] | 82 | */ |
| 83 | class CameraHardwareInterface : public virtual RefBase { |
| 84 | public: |
| 85 | virtual ~CameraHardwareInterface() { } |
| 86 | |
| 87 | /** Return the IMemoryHeap for the preview image heap */ |
| 88 | virtual sp<IMemoryHeap> getPreviewHeap() const = 0; |
| 89 | |
| 90 | /** Return the IMemoryHeap for the raw image heap */ |
| 91 | virtual sp<IMemoryHeap> getRawHeap() const = 0; |
| 92 | |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 93 | /** Set the notification and data callbacks */ |
| 94 | virtual void setCallbacks(notify_callback notify_cb, |
| 95 | data_callback data_cb, |
| 96 | data_callback_timestamp data_cb_timestamp, |
| 97 | void* user) = 0; |
| 98 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | /** |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 100 | * The following three functions all take a msgtype, |
| 101 | * which is a bitmask of the messages defined in |
| 102 | * include/ui/Camera.h |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | */ |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Enable a message, or set of messages. |
| 107 | */ |
| 108 | virtual void enableMsgType(int32_t msgType) = 0; |
| 109 | |
| 110 | /** |
| 111 | * Disable a message, or a set of messages. |
| 112 | */ |
| 113 | virtual void disableMsgType(int32_t msgType) = 0; |
| 114 | |
| 115 | /** |
| 116 | * Query whether a message, or a set of messages, is enabled. |
| 117 | * Note that this is operates as an AND, if any of the messages |
| 118 | * queried are off, this will return false. |
| 119 | */ |
| 120 | virtual bool msgTypeEnabled(int32_t msgType) = 0; |
| 121 | |
| 122 | /** |
| 123 | * Start preview mode. |
| 124 | */ |
| 125 | virtual status_t startPreview() = 0; |
| 126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | /** |
| 128 | * Only used if overlays are used for camera preview. |
| 129 | */ |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 130 | virtual bool useOverlay() {return false;} |
| 131 | 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] | 132 | |
| 133 | /** |
| 134 | * Stop a previously started preview. |
| 135 | */ |
| 136 | virtual void stopPreview() = 0; |
| 137 | |
| 138 | /** |
| 139 | * Returns true if preview is enabled. |
| 140 | */ |
| 141 | virtual bool previewEnabled() = 0; |
| 142 | |
| 143 | /** |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 144 | * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME |
| 145 | * 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] | 146 | * by calling releaseRecordingFrame(). |
| 147 | */ |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 148 | virtual status_t startRecording() = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | |
| 150 | /** |
| 151 | * Stop a previously started recording. |
| 152 | */ |
| 153 | virtual void stopRecording() = 0; |
| 154 | |
| 155 | /** |
| 156 | * Returns true if recording is enabled. |
| 157 | */ |
| 158 | virtual bool recordingEnabled() = 0; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 159 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | /** |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 161 | * 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] | 162 | */ |
| 163 | virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0; |
| 164 | |
| 165 | /** |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 166 | * Start auto focus, the notification callback routine is called |
| 167 | * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() |
| 168 | * 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] | 169 | */ |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 170 | virtual status_t autoFocus() = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | |
| 172 | /** |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 173 | * Cancels auto-focus function. If the auto-focus is still in progress, |
| 174 | * this function will cancel it. Whether the auto-focus is in progress |
| 175 | * or not, this function will return the focus position to the default. |
| 176 | * If the camera does not support auto-focus, this is a no-op. |
| 177 | */ |
| 178 | virtual status_t cancelAutoFocus() = 0; |
| 179 | |
| 180 | /** |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 181 | * Take a picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | */ |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 183 | virtual status_t takePicture() = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | |
| 185 | /** |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 186 | * Cancel a picture that was started with takePicture. Calling this |
| 187 | * 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] | 188 | */ |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 189 | virtual status_t cancelPicture() = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | |
| 191 | /** Set the camera parameters. */ |
| 192 | virtual status_t setParameters(const CameraParameters& params) = 0; |
| 193 | |
| 194 | /** Return the camera parameters. */ |
| 195 | virtual CameraParameters getParameters() const = 0; |
| 196 | |
| 197 | /** |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 198 | * Send command to camera driver. |
| 199 | */ |
| 200 | virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0; |
| 201 | |
| 202 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | * Release the hardware resources owned by this object. Note that this is |
| 204 | * *not* done in the destructor. |
| 205 | */ |
| 206 | virtual void release() = 0; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | /** |
| 209 | * Dump state of the camera hardware |
| 210 | */ |
| 211 | virtual status_t dump(int fd, const Vector<String16>& args) const = 0; |
| 212 | }; |
| 213 | |
| 214 | /** factory function to instantiate a camera hardware object */ |
| 215 | extern "C" sp<CameraHardwareInterface> openCameraHardware(); |
| 216 | |
| 217 | }; // namespace android |
| 218 | |
| 219 | #endif |