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 typedef typename TCamTraits::TCamConnectService TCamConnectService; 61 62 static sp<TCam> connect(int cameraId, 63 const String16& clientPackageName, 64 int clientUid); 65 virtual void disconnect(); 66 67 void setListener(const sp<TCamListener>& listener); 68 69 static int getNumberOfCameras(); 70 71 static status_t getCameraInfo(int cameraId, 72 /*out*/ 73 struct CameraInfo* cameraInfo); 74 75 static status_t addServiceListener( 76 const sp<ICameraServiceListener>& listener); 77 78 static status_t removeServiceListener( 79 const sp<ICameraServiceListener>& listener); 80 81 sp<TCamUser> remote(); 82 83 // Status is set to 'UNKNOWN_ERROR' after successful (re)connection 84 status_t getStatus(); 85 86 protected: 87 CameraBase(int cameraId); 88 virtual ~CameraBase(); 89 90 //////////////////////////////////////////////////////// 91 // TCamCallbacks implementation 92 //////////////////////////////////////////////////////// 93 virtual void notifyCallback(int32_t msgType, int32_t ext, 94 int32_t ext2); 95 96 //////////////////////////////////////////////////////// 97 // Common instance variables 98 //////////////////////////////////////////////////////// 99 Mutex mLock; 100 101 virtual void binderDied(const wp<IBinder>& who); 102 103 // helper function to obtain camera service handle 104 static const sp<ICameraService>& getCameraService(); 105 106 sp<TCamUser> mCamera; 107 status_t mStatus; 108 109 sp<TCamListener> mListener; 110 111 const int mCameraId; 112 113 typedef CameraBase<TCam> CameraBaseT; 114 }; 115 116 }; // namespace android 117 118 #endif 119