Home | History | Annotate | Download | only in camera
      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_H
     18 #define ANDROID_HARDWARE_CAMERA_H
     19 
     20 #include <utils/Timers.h>
     21 #include <gui/ISurfaceTexture.h>
     22 #include <system/camera.h>
     23 #include <camera/ICameraClient.h>
     24 #include <camera/ICameraRecordingProxy.h>
     25 #include <camera/ICameraRecordingProxyListener.h>
     26 
     27 namespace android {
     28 
     29 struct CameraInfo {
     30     /**
     31      * The direction that the camera faces to. It should be CAMERA_FACING_BACK
     32      * or CAMERA_FACING_FRONT.
     33      */
     34     int facing;
     35 
     36     /**
     37      * The orientation of the camera image. The value is the angle that the
     38      * camera image needs to be rotated clockwise so it shows correctly on the
     39      * display in its natural orientation. It should be 0, 90, 180, or 270.
     40      *
     41      * For example, suppose a device has a naturally tall screen. The
     42      * back-facing camera sensor is mounted in landscape. You are looking at
     43      * the screen. If the top side of the camera sensor is aligned with the
     44      * right edge of the screen in natural orientation, the value should be
     45      * 90. If the top side of a front-facing camera sensor is aligned with the
     46      * right of the screen, the value should be 270.
     47      */
     48     int orientation;
     49 };
     50 
     51 class ICameraService;
     52 class ICamera;
     53 class Surface;
     54 class Mutex;
     55 class String8;
     56 
     57 // ref-counted object for callbacks
     58 class CameraListener: virtual public RefBase
     59 {
     60 public:
     61     virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
     62     virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr,
     63                           camera_frame_metadata_t *metadata) = 0;
     64     virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
     65 };
     66 
     67 class Camera : public BnCameraClient, public IBinder::DeathRecipient
     68 {
     69 public:
     70             // construct a camera client from an existing remote
     71     static  sp<Camera>  create(const sp<ICamera>& camera);
     72     static  int32_t     getNumberOfCameras();
     73     static  status_t    getCameraInfo(int cameraId,
     74                                       struct CameraInfo* cameraInfo);
     75     static  sp<Camera>  connect(int cameraId);
     76             virtual     ~Camera();
     77             void        init();
     78 
     79             status_t    reconnect();
     80             void        disconnect();
     81             status_t    lock();
     82             status_t    unlock();
     83 
     84             status_t    getStatus() { return mStatus; }
     85 
     86             // pass the buffered Surface to the camera service
     87             status_t    setPreviewDisplay(const sp<Surface>& surface);
     88 
     89             // pass the buffered ISurfaceTexture to the camera service
     90             status_t    setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture);
     91 
     92             // start preview mode, must call setPreviewDisplay first
     93             status_t    startPreview();
     94 
     95             // stop preview mode
     96             void        stopPreview();
     97 
     98             // get preview state
     99             bool        previewEnabled();
    100 
    101             // start recording mode, must call setPreviewDisplay first
    102             status_t    startRecording();
    103 
    104             // stop recording mode
    105             void        stopRecording();
    106 
    107             // get recording state
    108             bool        recordingEnabled();
    109 
    110             // release a recording frame
    111             void        releaseRecordingFrame(const sp<IMemory>& mem);
    112 
    113             // autoFocus - status returned from callback
    114             status_t    autoFocus();
    115 
    116             // cancel auto focus
    117             status_t    cancelAutoFocus();
    118 
    119             // take a picture - picture returned from callback
    120             status_t    takePicture(int msgType);
    121 
    122             // set preview/capture parameters - key/value pairs
    123             status_t    setParameters(const String8& params);
    124 
    125             // get preview/capture parameters - key/value pairs
    126             String8     getParameters() const;
    127 
    128             // send command to camera driver
    129             status_t    sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
    130 
    131             // tell camera hal to store meta data or real YUV in video buffers.
    132             status_t    storeMetaDataInBuffers(bool enabled);
    133 
    134             void        setListener(const sp<CameraListener>& listener);
    135             void        setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener);
    136             void        setPreviewCallbackFlags(int preview_callback_flag);
    137 
    138             sp<ICameraRecordingProxy> getRecordingProxy();
    139 
    140     // ICameraClient interface
    141     virtual void        notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
    142     virtual void        dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
    143                                      camera_frame_metadata_t *metadata);
    144     virtual void        dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
    145 
    146     sp<ICamera>         remote();
    147 
    148     class RecordingProxy : public BnCameraRecordingProxy
    149     {
    150     public:
    151         RecordingProxy(const sp<Camera>& camera);
    152 
    153         // ICameraRecordingProxy interface
    154         virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
    155         virtual void stopRecording();
    156         virtual void releaseRecordingFrame(const sp<IMemory>& mem);
    157 
    158     private:
    159         sp<Camera>         mCamera;
    160     };
    161 
    162 private:
    163                         Camera();
    164                         Camera(const Camera&);
    165                         Camera& operator=(const Camera);
    166                         virtual void binderDied(const wp<IBinder>& who);
    167 
    168             class DeathNotifier: public IBinder::DeathRecipient
    169             {
    170             public:
    171                 DeathNotifier() {
    172                 }
    173 
    174                 virtual void binderDied(const wp<IBinder>& who);
    175             };
    176 
    177             static sp<DeathNotifier> mDeathNotifier;
    178 
    179             // helper function to obtain camera service handle
    180             static const sp<ICameraService>& getCameraService();
    181 
    182             sp<ICamera>         mCamera;
    183             status_t            mStatus;
    184 
    185             sp<CameraListener>  mListener;
    186             sp<ICameraRecordingProxyListener>  mRecordingProxyListener;
    187 
    188             friend class DeathNotifier;
    189 
    190             static  Mutex               mLock;
    191             static  sp<ICameraService>  mCameraService;
    192 };
    193 
    194 }; // namespace android
    195 
    196 #endif
    197