blob: d8561edd59e6822abbea30a38291e59fde56a5d4 [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:
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070057 typedef typename TCamTraits::TCamListener TCamListener;
58 typedef typename TCamTraits::TCamUser TCamUser;
59 typedef typename TCamTraits::TCamCallbacks TCamCallbacks;
60 typedef typename TCamTraits::TCamConnectService TCamConnectService;
Igor Murashkinc073ba52013-02-26 14:32:34 -080061
62 static sp<TCam> connect(int cameraId,
63 const String16& clientPackageName,
Chien-Yu Chen98a668f2015-12-18 14:10:33 -080064 int clientUid, int clientPid);
Igor Murashkinc073ba52013-02-26 14:32:34 -080065 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
Igor Murashkinbfc99152013-02-27 12:55:20 -080075 static status_t addServiceListener(
76 const sp<ICameraServiceListener>& listener);
77
78 static status_t removeServiceListener(
79 const sp<ICameraServiceListener>& listener);
80
Igor Murashkinc073ba52013-02-26 14:32:34 -080081 sp<TCamUser> remote();
82
83 // Status is set to 'UNKNOWN_ERROR' after successful (re)connection
84 status_t getStatus();
85
86protected:
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);
Igor Murashkinc073ba52013-02-26 14:32:34 -080095
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
Igor Murashkinfa4cf9d2013-03-04 16:14:23 -0800113 typedef CameraBase<TCam> CameraBaseT;
Igor Murashkinc073ba52013-02-26 14:32:34 -0800114};
115
116}; // namespace android
117
118#endif