blob: 0692a2711f63e4d61023eca9147bf61a5b765f46 [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>
Igor Murashkinc073ba52013-02-26 14:32:34 -080021
22struct camera_frame_metadata;
23
24namespace android {
25
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080026namespace hardware {
27
28
29class ICameraService;
30class ICameraServiceListener;
31
32struct CameraInfo : public android::Parcelable {
Igor Murashkinc073ba52013-02-26 14:32:34 -080033 /**
34 * The direction that the camera faces to. It should be CAMERA_FACING_BACK
35 * or CAMERA_FACING_FRONT.
36 */
37 int facing;
38
39 /**
40 * The orientation of the camera image. The value is the angle that the
41 * camera image needs to be rotated clockwise so it shows correctly on the
42 * display in its natural orientation. It should be 0, 90, 180, or 270.
43 *
44 * For example, suppose a device has a naturally tall screen. The
45 * back-facing camera sensor is mounted in landscape. You are looking at
46 * the screen. If the top side of the camera sensor is aligned with the
47 * right edge of the screen in natural orientation, the value should be
48 * 90. If the top side of a front-facing camera sensor is aligned with the
49 * right of the screen, the value should be 270.
50 */
51 int orientation;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080052
53 virtual status_t writeToParcel(Parcel* parcel) const;
54 virtual status_t readFromParcel(const Parcel* parcel);
55
Igor Murashkinc073ba52013-02-26 14:32:34 -080056};
57
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080058} // namespace hardware
59
60using hardware::CameraInfo;
61
62
Igor Murashkinc073ba52013-02-26 14:32:34 -080063template <typename TCam>
64struct CameraTraits {
65};
66
67template <typename TCam, typename TCamTraits = CameraTraits<TCam> >
68class CameraBase : public IBinder::DeathRecipient
69{
70public:
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070071 typedef typename TCamTraits::TCamListener TCamListener;
72 typedef typename TCamTraits::TCamUser TCamUser;
73 typedef typename TCamTraits::TCamCallbacks TCamCallbacks;
74 typedef typename TCamTraits::TCamConnectService TCamConnectService;
Igor Murashkinc073ba52013-02-26 14:32:34 -080075
76 static sp<TCam> connect(int cameraId,
77 const String16& clientPackageName,
Chien-Yu Chen98a668f2015-12-18 14:10:33 -080078 int clientUid, int clientPid);
Igor Murashkinc073ba52013-02-26 14:32:34 -080079 virtual void disconnect();
80
81 void setListener(const sp<TCamListener>& listener);
82
83 static int getNumberOfCameras();
84
85 static status_t getCameraInfo(int cameraId,
86 /*out*/
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080087 struct hardware::CameraInfo* cameraInfo);
Igor Murashkinc073ba52013-02-26 14:32:34 -080088
Igor Murashkinbfc99152013-02-27 12:55:20 -080089 static status_t addServiceListener(
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080090 const sp<::android::hardware::ICameraServiceListener>& listener);
Igor Murashkinbfc99152013-02-27 12:55:20 -080091
92 static status_t removeServiceListener(
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080093 const sp<::android::hardware::ICameraServiceListener>& listener);
Igor Murashkinbfc99152013-02-27 12:55:20 -080094
Igor Murashkinc073ba52013-02-26 14:32:34 -080095 sp<TCamUser> remote();
96
97 // Status is set to 'UNKNOWN_ERROR' after successful (re)connection
98 status_t getStatus();
99
100protected:
101 CameraBase(int cameraId);
102 virtual ~CameraBase();
103
104 ////////////////////////////////////////////////////////
105 // TCamCallbacks implementation
106 ////////////////////////////////////////////////////////
107 virtual void notifyCallback(int32_t msgType, int32_t ext,
108 int32_t ext2);
Igor Murashkinc073ba52013-02-26 14:32:34 -0800109
110 ////////////////////////////////////////////////////////
111 // Common instance variables
112 ////////////////////////////////////////////////////////
113 Mutex mLock;
114
115 virtual void binderDied(const wp<IBinder>& who);
116
117 // helper function to obtain camera service handle
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800118 static const sp<::android::hardware::ICameraService>& getCameraService();
Igor Murashkinc073ba52013-02-26 14:32:34 -0800119
120 sp<TCamUser> mCamera;
121 status_t mStatus;
122
123 sp<TCamListener> mListener;
124
125 const int mCameraId;
126
Igor Murashkinfa4cf9d2013-03-04 16:14:23 -0800127 typedef CameraBase<TCam> CameraBaseT;
Igor Murashkinc073ba52013-02-26 14:32:34 -0800128};
129
130}; // namespace android
131
132#endif