blob: fed28ea1d9122edd73a2f2cf7ea177861e28d570 [file] [log] [blame]
Igor Murashkinc073ba52013-02-26 14:32:34 -08001/*
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 sp<TCamUser> remote();
75
76 // Status is set to 'UNKNOWN_ERROR' after successful (re)connection
77 status_t getStatus();
78
79protected:
80 CameraBase(int cameraId);
81 virtual ~CameraBase();
82
83 ////////////////////////////////////////////////////////
84 // TCamCallbacks implementation
85 ////////////////////////////////////////////////////////
86 virtual void notifyCallback(int32_t msgType, int32_t ext,
87 int32_t ext2);
88 virtual void dataCallback(int32_t msgType,
89 const sp<IMemory>& dataPtr,
90 camera_frame_metadata *metadata);
91 bool dataCallbackTimestamp(nsecs_t timestamp,
92 int32_t msgType,
93 const sp<IMemory>& dataPtr);
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