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