The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [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 | |
| 24 | namespace android { |
| 25 | |
| 26 | /** Callback for startPreview() */ |
| 27 | typedef void (*preview_callback)(const sp<IMemory>& mem, void* user); |
| 28 | |
| 29 | /** Callback for takePicture() */ |
| 30 | typedef void (*shutter_callback)(void* user); |
| 31 | |
| 32 | /** Callback for takePicture() */ |
| 33 | typedef void (*raw_callback)(const sp<IMemory>& mem, void* user); |
| 34 | |
| 35 | /** Callback for takePicture() */ |
| 36 | typedef void (*jpeg_callback)(const sp<IMemory>& mem, void* user); |
| 37 | |
| 38 | /** Callback for autoFocus() */ |
| 39 | typedef void (*autofocus_callback)(bool focused, void* user); |
| 40 | |
| 41 | /** |
| 42 | * This defines the interface to the camera hardware abstraction |
| 43 | * layer. It supports setting and getting parameters, live |
| 44 | * previewing and taking pictures. It is a referenced counted |
| 45 | * interface with RefBase as its base class. |
| 46 | * |
| 47 | * The openCameraHardware function is used to |
| 48 | * retrieve a strong pointer to the instance of this interface |
| 49 | * and may be called multiple times. |
| 50 | * |
| 51 | * After calling openCameraHardware the getParameters and |
| 52 | * setParameters are used to initialize the camera instance. |
| 53 | * |
| 54 | * Then getPreviewHeap is called to get access to the preview |
| 55 | * heap so it can be registered with the SurfaceFlinger for efficient |
| 56 | * display updating while in the preview mode. |
| 57 | * |
| 58 | * Next startPreview is called which is passed a preview_callback |
| 59 | * function and a user parameter. The camera instance then |
| 60 | * periodically calls preview_callback each time a new |
| 61 | * preview frame is available. The call back routine has |
| 62 | * two parameters, the first is a pointer to the the IMemory containing |
| 63 | * the frame and the other is the user parameter. If the preview_callback |
| 64 | * code needs to use this memory after returning it must copy |
| 65 | * the data. |
| 66 | * |
| 67 | * Prior to taking a picture the autoFocus method is usually called with a |
| 68 | * autofocus_callback and a user parameter. When auto focusing |
| 69 | * has completed the camera instance calls autofocus_callback which |
| 70 | * informs the application if focusing was successful or not. |
| 71 | * The camera instance only calls the autofocus_callback once and it |
| 72 | * is up to the application to call autoFocus again if refocusing is desired. |
| 73 | * |
| 74 | * The method takePicture is called to request that the camera instance take a |
| 75 | * picture. This method has three callbacks: shutter_callback, raw_callback, |
| 76 | * and jpeg_callback. As soon as the shutter snaps and it is safe to move the |
| 77 | * camera, shutter_callback is called. Typically, you would want to play the |
| 78 | * shutter sound at this moment. Later, when the raw image is available the |
| 79 | * raw_callback is called with a pointer to the IMemory containing the raw |
| 80 | * image. Finally, when the encoded jpeg image is available the jpeg_callback |
| 81 | * will be called with a pointer to the IMemory containing the jpeg image. As |
| 82 | * with the preview_callback the memory must be copied if it's needed after |
| 83 | * returning. |
| 84 | */ |
| 85 | class CameraHardwareInterface : public virtual RefBase { |
| 86 | public: |
| 87 | virtual ~CameraHardwareInterface() { } |
| 88 | |
| 89 | /** Return the IMemoryHeap for the preview image heap */ |
| 90 | virtual sp<IMemoryHeap> getPreviewHeap() const = 0; |
| 91 | |
| 92 | /** |
| 93 | * Start preview mode. When a preview image is available |
| 94 | * preview_callback is called with the user parameter. The |
| 95 | * call back parameter may be null. |
| 96 | */ |
| 97 | virtual status_t startPreview(preview_callback cb, void* user) = 0; |
| 98 | |
| 99 | /** |
| 100 | * Stop a previously started preview. |
| 101 | */ |
| 102 | virtual void stopPreview() = 0; |
| 103 | |
| 104 | /** |
| 105 | * Start auto focus, the callback routine is called |
| 106 | * once when focusing is complete. autoFocus() will |
| 107 | * be called agained if another auto focus is needed. |
| 108 | */ |
| 109 | virtual status_t autoFocus(autofocus_callback, |
| 110 | void* user) = 0; |
| 111 | |
| 112 | /** |
| 113 | * Take a picture. The raw_callback is called when |
| 114 | * the uncompressed image is available. The jpeg_callback |
| 115 | * is called when the compressed image is available. These |
| 116 | * call backs may be null. The user parameter is passed |
| 117 | * to each of the call back routines. |
| 118 | */ |
| 119 | virtual status_t takePicture(shutter_callback, |
| 120 | raw_callback, |
| 121 | jpeg_callback, |
| 122 | void* user) = 0; |
| 123 | |
| 124 | /** |
| 125 | * Cancel a picture that was started with takePicture. You may cancel any |
| 126 | * of the shutter, raw, or jpeg callbacks. Calling this method when no |
| 127 | * picture is being taken is a no-op. |
| 128 | */ |
| 129 | virtual status_t cancelPicture(bool cancel_shutter, |
| 130 | bool cancel_raw, |
| 131 | bool cancel_jpeg) = 0; |
| 132 | |
| 133 | /** Set the camera parameters. */ |
| 134 | virtual status_t setParameters(const CameraParameters& params) = 0; |
| 135 | |
| 136 | /** Return the camera parameters. */ |
| 137 | virtual CameraParameters getParameters() const = 0; |
| 138 | |
| 139 | /** |
| 140 | * Release the hardware resources owned by this object. Note that this is |
| 141 | * *not* done in the destructor. |
| 142 | */ |
| 143 | virtual void release() = 0; |
| 144 | |
| 145 | /** |
| 146 | * Dump state of the camera hardware |
| 147 | */ |
| 148 | virtual status_t dump(int fd, const Vector<String16>& args) const = 0; |
| 149 | }; |
| 150 | |
| 151 | /** factory function to instantiate a camera hardware object */ |
| 152 | extern "C" sp<CameraHardwareInterface> openCameraHardware(); |
| 153 | |
| 154 | }; // namespace android |
| 155 | |
| 156 | #endif |