• Main Page
  • Namespaces
  • Data Structures
  • Files

CameraHardwareInterface.h

Go to the documentation of this file.
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 #include <ui/Overlay.h>
00024 
00025 namespace android {
00026 
00027 /** Callback for startPreview() */
00028 typedef void (*preview_callback)(const sp<IMemory>& mem, void* user);
00029 
00030 /** Callback for startRecord() */
00031 typedef void (*recording_callback)(nsecs_t timestamp, const sp<IMemory>& mem, void* user);
00032 
00033 /** Callback for takePicture() */
00034 typedef void (*shutter_callback)(void* user);
00035 
00036 /** Callback for takePicture() */
00037 typedef void (*raw_callback)(const sp<IMemory>& mem, void* user);
00038 
00039 /** Callback for takePicture() */
00040 typedef void (*jpeg_callback)(const sp<IMemory>& mem, void* user);
00041 
00042 /** Callback for autoFocus() */
00043 typedef void (*autofocus_callback)(bool focused, void* user);
00044 
00045 /**
00046  * CameraHardwareInterface.h defines the interface to the
00047  * camera hardware abstraction layer, used for setting and getting
00048  * parameters, live previewing, and taking pictures.
00049  *
00050  * It is a referenced counted interface with RefBase as its base class.
00051  * CameraService calls openCameraHardware() to retrieve a strong pointer to the
00052  * instance of this interface and may be called multiple times. The
00053  * following steps describe a typical sequence:
00054  *
00055  *   -# After CameraService calls openCameraHardware(), getParameters() and
00056  *      setParameters() are used to initialize the camera instance.
00057  *      CameraService calls getPreviewHeap() to establish access to the
00058  *      preview heap so it can be registered with SurfaceFlinger for
00059  *      efficient display updating while in preview mode.
00060  *   -# startPreview() is called, which is passed a preview_callback()
00061  *      function and a user parameter. The camera instance then periodically
00062  *      calls preview_callback() each time a new preview frame is available.
00063  *      The callback routine has two parameters: the first is a pointer to
00064  *      the IMemory containing the frame and the second a user parameter. If
00065  *      the preview_callback code needs to use this memory after returning,
00066  *      it must copy the data.
00067  *
00068  * Prior to taking a picture, CameraService calls autofocus() with
00069  * autofocus_callback() and a user parameter. When auto focusing has
00070  * completed, the camera instance calls autofocus_callback(), which informs
00071  * the application whether focusing was successful. The camera instance
00072  * only calls autofocus_callback() once and it is up to the application to
00073  * call autoFocus() again if refocusing is desired.
00074  *
00075  * CameraService calls takePicture() to request the camera instance take a
00076  * picture. This method has two callbacks: raw_callback() and jpeg_callback().
00077  * When the raw image is available, raw_callback() is called with a pointer
00078  * to the IMemory containing the raw image. When the jpeg image is available,
00079  * jpeg_callback() is called with a pointer to the IMemory containing the
00080  * jpeg image. As with preview_callback(), the memory must be copied if it's
00081  * needed after returning.
00082  */
00083 class CameraHardwareInterface : public virtual RefBase {
00084 public:
00085     virtual ~CameraHardwareInterface() { }
00086 
00087     /** Return the IMemoryHeap for the preview image heap */
00088     virtual sp<IMemoryHeap>         getPreviewHeap() const = 0;
00089 
00090     /** Return the IMemoryHeap for the raw image heap */
00091     virtual sp<IMemoryHeap>         getRawHeap() const = 0;
00092 
00093     /**
00094      * Start preview mode. When a preview image is available
00095      * preview_callback is called with the user parameter. The
00096      * call back parameter may be null.
00097      */
00098     virtual status_t    startPreview(preview_callback cb, void* user) = 0;
00099     /**
00100      * Only used if overlays are used for camera preview.
00101      */
00102     virtual bool useOverlay() {return false;}
00103     virtual status_t setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;}
00104 
00105     /**
00106      * Stop a previously started preview.
00107      */
00108     virtual void        stopPreview() = 0;
00109 
00110     /**
00111      * Returns true if preview is enabled.
00112      */
00113     virtual bool        previewEnabled() = 0;
00114 
00115     /**
00116      * Start record mode. When a record image is available recording_callback()
00117      * is called with the user parameter.  Every record frame must be released
00118      * by calling releaseRecordingFrame().
00119      */
00120     virtual status_t    startRecording(recording_callback cb, void* user) = 0;
00121 
00122     /**
00123      * Stop a previously started recording.
00124      */
00125     virtual void        stopRecording() = 0;
00126 
00127     /**
00128      * Returns true if recording is enabled.
00129      */
00130     virtual bool        recordingEnabled() = 0;
00131     
00132     /**
00133      * Release a record frame previously returned by the recording_callback()
00134      * passed to startRecord().
00135      */
00136     virtual void        releaseRecordingFrame(const sp<IMemory>& mem) = 0;
00137 
00138     /**
00139      * Start auto focus, the callback routine is called
00140      * once when focusing is complete. autoFocus() will
00141      * be called again if another auto focus is needed.
00142      */
00143     virtual status_t    autoFocus(autofocus_callback,
00144                                   void* user) = 0;
00145 
00146     /**
00147      * Take a picture. The raw_callback is called when
00148      * the uncompressed image is available. The jpeg_callback
00149      * is called when the compressed image is available. These
00150      * call backs may be null. The user parameter is passed
00151      * to each of the call back routines.
00152      */
00153     virtual status_t    takePicture(shutter_callback,
00154                                     raw_callback,
00155                                     jpeg_callback,
00156                                     void* user) = 0;
00157 
00158     /**
00159      * Cancel a picture that was started with takePicture.  You may cancel any
00160      * of the shutter, raw, or jpeg callbacks.  Calling this method when no
00161      * picture is being taken is a no-op.
00162      */
00163     virtual status_t    cancelPicture(bool cancel_shutter,
00164                                       bool cancel_raw,
00165                                       bool cancel_jpeg) = 0;
00166 
00167     /** Set the camera parameters. */
00168     virtual status_t    setParameters(const CameraParameters& params) = 0;
00169 
00170     /** Return the camera parameters. */
00171     virtual CameraParameters  getParameters() const = 0;
00172 
00173     /**
00174      * Release the hardware resources owned by this object.  Note that this is
00175      * *not* done in the destructor.
00176      */
00177     virtual void release() = 0;
00178     
00179     /**
00180      * Dump state of the camera hardware
00181      */
00182     virtual status_t dump(int fd, const Vector<String16>& args) const = 0;
00183 };
00184 
00185 /** factory function to instantiate a camera hardware object */
00186 extern "C" sp<CameraHardwareInterface> openCameraHardware();
00187 
00188 };  // namespace android
00189 
00190 #endif