00001 /* 00002 * Copyright (C) 2008 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H 00018 #define ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H 00019 00020 #include <utils/IMemory.h> 00021 #include <utils/RefBase.h> 00022 #include <ui/CameraParameters.h> 00023 00024 namespace android { 00025 00026 /** Callback for startPreview() */ 00027 typedef void (*preview_callback)(const sp<IMemory>& mem, void* user); 00028 00029 /** Callback for takePicture() */ 00030 typedef void (*shutter_callback)(void* user); 00031 00032 /** Callback for takePicture() */ 00033 typedef void (*raw_callback)(const sp<IMemory>& mem, void* user); 00034 00035 /** Callback for takePicture() */ 00036 typedef void (*jpeg_callback)(const sp<IMemory>& mem, void* user); 00037 00038 /** Callback for autoFocus() */ 00039 typedef void (*autofocus_callback)(bool focused, void* user); 00040 00041 /** 00042 * CameraHardwareInterface.h defines the interface to the 00043 * camera hardware abstraction layer, used for setting and getting 00044 * parameters, live previewing, and taking pictures. 00045 * 00046 * It is a referenced counted interface with RefBase as its base class. 00047 * CameraService calls openCameraHardware() to retrieve a strong pointer to the 00048 * instance of this interface and may be called multiple times. The 00049 * following steps describe a typical sequence: 00050 * 00051 * -# After CameraService calls openCameraHardware(), getParameters() and 00052 * setParameters() are used to initialize the camera instance. 00053 * CameraService calls getPreviewHeap() to establish access to the 00054 * preview heap so it can be registered with SurfaceFlinger for 00055 * efficient display updating while in preview mode. 00056 * -# startPreview() is called, which is passed a preview_callback() 00057 * function and a user parameter. The camera instance then periodically 00058 * calls preview_callback() each time a new preview frame is available. 00059 * The callback routine has two parameters: the first is a pointer to 00060 * the IMemory containing the frame and the second a user parameter. If 00061 * the preview_callback code needs to use this memory after returning, 00062 * it must copy the data. 00063 * 00064 * Prior to taking a picture, CameraService calls autofocus() with 00065 * autofocus_callback() and a user parameter. When auto focusing has 00066 * completed, the camera instance calls autofocus_callback(), which informs 00067 * the application whether focusing was successful. The camera instance 00068 * only calls autofocus_callback() once and it is up to the application to 00069 * call autoFocus() again if refocusing is desired. 00070 * 00071 * CameraService calls takePicture() to request the camera instance take a 00072 * picture. This method has two callbacks: raw_callback() and jpeg_callback(). 00073 * When the raw image is available, raw_callback() is called with a pointer 00074 * to the IMemory containing the raw image. When the jpeg image is available, 00075 * jpeg_callback() is called with a pointer to the IMemory containing the 00076 * jpeg image. As with preview_callback(), the memory must be copied if it's 00077 * needed after returning. 00078 */ 00079 class CameraHardwareInterface : public virtual RefBase { 00080 public: 00081 virtual ~CameraHardwareInterface() { } 00082 00083 /** Return the IMemoryHeap for the preview image heap */ 00084 virtual sp<IMemoryHeap> getPreviewHeap() const = 0; 00085 00086 /** 00087 * Start preview mode. When a preview image is available 00088 * preview_callback is called with the user parameter. The 00089 * call back parameter may be null. 00090 */ 00091 virtual status_t startPreview(preview_callback cb, void* user) = 0; 00092 00093 /** 00094 * Stop a previously started preview. 00095 */ 00096 virtual void stopPreview() = 0; 00097 00098 /** 00099 * Start auto focus, the callback routine is called 00100 * once when focusing is complete. autoFocus() will 00101 * be called again if another auto focus is needed. 00102 */ 00103 virtual status_t autoFocus(autofocus_callback, 00104 void* user) = 0; 00105 00106 /** 00107 * Take a picture. The raw_callback is called when 00108 * the uncompressed image is available. The jpeg_callback 00109 * is called when the compressed image is available. These 00110 * call backs may be null. The user parameter is passed 00111 * to each of the call back routines. 00112 */ 00113 virtual status_t takePicture(shutter_callback, 00114 raw_callback, 00115 jpeg_callback, 00116 void* user) = 0; 00117 00118 /** 00119 * Cancel a picture that was started with takePicture. You may cancel any 00120 * of the shutter, raw, or jpeg callbacks. Calling this method when no 00121 * picture is being taken is a no-op. 00122 */ 00123 virtual status_t cancelPicture(bool cancel_shutter, 00124 bool cancel_raw, 00125 bool cancel_jpeg) = 0; 00126 00127 /** Set the camera parameters. */ 00128 virtual status_t setParameters(const CameraParameters& params) = 0; 00129 00130 /** Return the camera parameters. */ 00131 virtual CameraParameters getParameters() const = 0; 00132 00133 /** 00134 * Release the hardware resources owned by this object. Note that this is 00135 * *not* done in the destructor. 00136 */ 00137 virtual void release() = 0; 00138 00139 /** 00140 * Dump state of the camera hardware 00141 */ 00142 virtual status_t dump(int fd, const Vector<String16>& args) const = 0; 00143 }; 00144 00145 /** factory function to instantiate a camera hardware object */ 00146 extern "C" sp<CameraHardwareInterface> openCameraHardware(); 00147 00148 }; // namespace android 00149 00150 #endif