CameraBase.h revision 8fdfbe27acd157d58fa35a849ec50c82464062f0
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 23struct camera_frame_metadata; 24 25namespace android { 26 27struct 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 49template <typename TCam> 50struct CameraTraits { 51}; 52 53template <typename TCam, typename TCamTraits = CameraTraits<TCam> > 54class CameraBase : public IBinder::DeathRecipient 55{ 56public: 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 85protected: 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 virtual void dataCallback(int32_t msgType, 95 const sp<IMemory>& dataPtr, 96 camera_frame_metadata *metadata); 97 bool dataCallbackTimestamp(nsecs_t timestamp, 98 int32_t msgType, 99 const sp<IMemory>& dataPtr); 100 101 //////////////////////////////////////////////////////// 102 // Common instance variables 103 //////////////////////////////////////////////////////// 104 Mutex mLock; 105 106 virtual void binderDied(const wp<IBinder>& who); 107 108 // helper function to obtain camera service handle 109 static const sp<ICameraService>& getCameraService(); 110 111 sp<TCamUser> mCamera; 112 status_t mStatus; 113 114 sp<TCamListener> mListener; 115 116 const int mCameraId; 117 118 typedef CameraBase<TCam> CameraBaseT; 119}; 120 121}; // namespace android 122 123#endif 124