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 | |
| 20 | #include <utils/IMemory.h> |
| 21 | #include <utils/RefBase.h> |
| 22 | #include <ui/CameraParameters.h> |
| 23 | #include <ui/Overlay.h> |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | /** Callback for startPreview() */ |
| 28 | typedef void (*preview_callback)(const sp<IMemory>& mem, void* user); |
| 29 | |
| 30 | /** Callback for startRecord() */ |
| 31 | typedef void (*recording_callback)(const sp<IMemory>& mem, void* user); |
| 32 | |
| 33 | /** Callback for takePicture() */ |
| 34 | typedef void (*shutter_callback)(void* user); |
| 35 | |
| 36 | /** Callback for takePicture() */ |
| 37 | typedef void (*raw_callback)(const sp<IMemory>& mem, void* user); |
| 38 | |
| 39 | /** Callback for takePicture() */ |
| 40 | typedef void (*jpeg_callback)(const sp<IMemory>& mem, void* user); |
| 41 | |
| 42 | /** Callback for autoFocus() */ |
| 43 | typedef void (*autofocus_callback)(bool focused, 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, which is passed a preview_callback() |
| 61 | * function and a user parameter. The camera instance then periodically |
| 62 | * calls preview_callback() each time a new preview frame is available. |
| 63 | * The callback routine has two parameters: the first is a pointer to |
| 64 | * the IMemory containing the frame and the second a user parameter. If |
| 65 | * the preview_callback code needs to use this memory after returning, |
| 66 | * it must copy the data. |
| 67 | * |
| 68 | * Prior to taking a picture, CameraService calls autofocus() with |
| 69 | * autofocus_callback() and a user parameter. When auto focusing has |
| 70 | * completed, the camera instance calls autofocus_callback(), which informs |
| 71 | * the application whether focusing was successful. The camera instance |
| 72 | * only calls autofocus_callback() once and it is up to the application to |
| 73 | * call autoFocus() again if refocusing is desired. |
| 74 | * |
| 75 | * CameraService calls takePicture() to request the camera instance take a |
| 76 | * picture. This method has two callbacks: raw_callback() and jpeg_callback(). |
| 77 | * When the raw image is available, raw_callback() is called with a pointer |
| 78 | * to the IMemory containing the raw image. When the jpeg image is available, |
| 79 | * jpeg_callback() is called with a pointer to the IMemory containing the |
| 80 | * jpeg image. As with preview_callback(), the memory must be copied if it's |
| 81 | * needed after returning. |
| 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 | |
| 93 | /** |
| 94 | * Start preview mode. When a preview image is available |
| 95 | * preview_callback is called with the user parameter. The |
| 96 | * call back parameter may be null. |
| 97 | */ |
| 98 | virtual status_t startPreview(preview_callback cb, void* user) = 0; |
| 99 | /** |
| 100 | * Only used if overlays are used for camera preview. |
| 101 | */ |
| 102 | virtual bool useOverlay() {return false;} |
| 103 | virtual status_t setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;} |
| 104 | |
| 105 | /** |
| 106 | * Stop a previously started preview. |
| 107 | */ |
| 108 | virtual void stopPreview() = 0; |
| 109 | |
| 110 | /** |
| 111 | * Returns true if preview is enabled. |
| 112 | */ |
| 113 | virtual bool previewEnabled() = 0; |
| 114 | |
| 115 | /** |
| 116 | * Start record mode. When a record image is available recording_callback() |
| 117 | * is called with the user parameter. Every record frame must be released |
| 118 | * by calling releaseRecordingFrame(). |
| 119 | */ |
| 120 | virtual status_t startRecording(recording_callback cb, void* user) = 0; |
| 121 | |
| 122 | /** |
| 123 | * Stop a previously started recording. |
| 124 | */ |
| 125 | virtual void stopRecording() = 0; |
| 126 | |
| 127 | /** |
| 128 | * Returns true if recording is enabled. |
| 129 | */ |
| 130 | virtual bool recordingEnabled() = 0; |
| 131 | |
| 132 | /** |
| 133 | * Release a record frame previously returned by the recording_callback() |
| 134 | * passed to startRecord(). |
| 135 | */ |
| 136 | virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0; |
| 137 | |
| 138 | /** |
| 139 | * Start auto focus, the callback routine is called |
| 140 | * once when focusing is complete. autoFocus() will |
| 141 | * be called again if another auto focus is needed. |
| 142 | */ |
| 143 | virtual status_t autoFocus(autofocus_callback, |
| 144 | void* user) = 0; |
| 145 | |
| 146 | /** |
| 147 | * Take a picture. The raw_callback is called when |
| 148 | * the uncompressed image is available. The jpeg_callback |
| 149 | * is called when the compressed image is available. These |
| 150 | * call backs may be null. The user parameter is passed |
| 151 | * to each of the call back routines. |
| 152 | */ |
| 153 | virtual status_t takePicture(shutter_callback, |
| 154 | raw_callback, |
| 155 | jpeg_callback, |
| 156 | void* user) = 0; |
| 157 | |
| 158 | /** |
| 159 | * Cancel a picture that was started with takePicture. You may cancel any |
| 160 | * of the shutter, raw, or jpeg callbacks. Calling this method when no |
| 161 | * picture is being taken is a no-op. |
| 162 | */ |
| 163 | virtual status_t cancelPicture(bool cancel_shutter, |
| 164 | bool cancel_raw, |
| 165 | bool cancel_jpeg) = 0; |
| 166 | |
| 167 | /** Set the camera parameters. */ |
| 168 | virtual status_t setParameters(const CameraParameters& params) = 0; |
| 169 | |
| 170 | /** Return the camera parameters. */ |
| 171 | virtual CameraParameters getParameters() const = 0; |
| 172 | |
| 173 | /** |
| 174 | * Release the hardware resources owned by this object. Note that this is |
| 175 | * *not* done in the destructor. |
| 176 | */ |
| 177 | virtual void release() = 0; |
| 178 | |
| 179 | /** |
| 180 | * Dump state of the camera hardware |
| 181 | */ |
| 182 | virtual status_t dump(int fd, const Vector<String16>& args) const = 0; |
| 183 | }; |
| 184 | |
| 185 | /** factory function to instantiate a camera hardware object */ |
| 186 | extern "C" sp<CameraHardwareInterface> openCameraHardware(); |
| 187 | |
| 188 | }; // namespace android |
| 189 | |
| 190 | #endif |