Home | History | Annotate | Download | only in camera
      1 /*
      2  * Copyright (C) 2013 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_BASE_H
     18 #define ANDROID_HARDWARE_CAMERA_BASE_H
     19 
     20 #include <utils/Mutex.h>
     21 #include <camera/ICameraService.h>
     22 
     23 struct camera_frame_metadata;
     24 
     25 namespace android {
     26 
     27 struct CameraInfo {
     28     /**
     29      * The direction that the camera faces to. It should be CAMERA_FACING_BACK
     30      * or CAMERA_FACING_FRONT.
     31      */
     32     int facing;
     33 
     34     /**
     35      * The orientation of the camera image. The value is the angle that the
     36      * camera image needs to be rotated clockwise so it shows correctly on the
     37      * display in its natural orientation. It should be 0, 90, 180, or 270.
     38      *
     39      * For example, suppose a device has a naturally tall screen. The
     40      * back-facing camera sensor is mounted in landscape. You are looking at
     41      * the screen. If the top side of the camera sensor is aligned with the
     42      * right edge of the screen in natural orientation, the value should be
     43      * 90. If the top side of a front-facing camera sensor is aligned with the
     44      * right of the screen, the value should be 270.
     45      */
     46     int orientation;
     47 };
     48 
     49 template <typename TCam>
     50 struct CameraTraits {
     51 };
     52 
     53 template <typename TCam, typename TCamTraits = CameraTraits<TCam> >
     54 class CameraBase : public IBinder::DeathRecipient
     55 {
     56 public:
     57     typedef typename TCamTraits::TCamListener    TCamListener;
     58     typedef typename TCamTraits::TCamUser        TCamUser;
     59     typedef typename TCamTraits::TCamCallbacks   TCamCallbacks;
     60 
     61     static sp<TCam>      connect(int cameraId,
     62                                  const String16& clientPackageName,
     63                                  int clientUid);
     64     virtual void         disconnect();
     65 
     66     void                 setListener(const sp<TCamListener>& listener);
     67 
     68     static int           getNumberOfCameras();
     69 
     70     static status_t      getCameraInfo(int cameraId,
     71                                        /*out*/
     72                                        struct CameraInfo* cameraInfo);
     73 
     74     static status_t      addServiceListener(
     75                                     const sp<ICameraServiceListener>& listener);
     76 
     77     static status_t      removeServiceListener(
     78                                     const sp<ICameraServiceListener>& listener);
     79 
     80     sp<TCamUser>         remote();
     81 
     82     // Status is set to 'UNKNOWN_ERROR' after successful (re)connection
     83     status_t             getStatus();
     84 
     85 protected:
     86     CameraBase(int cameraId);
     87     virtual              ~CameraBase();
     88 
     89     ////////////////////////////////////////////////////////
     90     // TCamCallbacks implementation
     91     ////////////////////////////////////////////////////////
     92     virtual void         notifyCallback(int32_t msgType, int32_t ext,
     93                                         int32_t ext2);
     94 
     95     ////////////////////////////////////////////////////////
     96     // Common instance variables
     97     ////////////////////////////////////////////////////////
     98     Mutex                            mLock;
     99 
    100     virtual void                     binderDied(const wp<IBinder>& who);
    101 
    102     // helper function to obtain camera service handle
    103     static const sp<ICameraService>& getCameraService();
    104 
    105     sp<TCamUser>                     mCamera;
    106     status_t                         mStatus;
    107 
    108     sp<TCamListener>                 mListener;
    109 
    110     const int                        mCameraId;
    111 
    112     typedef CameraBase<TCam>         CameraBaseT;
    113 };
    114 
    115 }; // namespace android
    116 
    117 #endif
    118