Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 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 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 20 | #include <android/hardware/ICameraServiceListener.h> |
| 21 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 22 | #include <utils/Mutex.h> |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 23 | #include <binder/BinderService.h> |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 24 | |
| 25 | struct camera_frame_metadata; |
| 26 | |
| 27 | namespace android { |
| 28 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 29 | namespace hardware { |
| 30 | |
| 31 | |
| 32 | class ICameraService; |
| 33 | class ICameraServiceListener; |
| 34 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 35 | enum { |
| 36 | /** The facing of the camera is opposite to that of the screen. */ |
| 37 | CAMERA_FACING_BACK = 0, |
| 38 | /** The facing of the camera is the same as that of the screen. */ |
| 39 | CAMERA_FACING_FRONT = 1, |
| 40 | }; |
| 41 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 42 | struct CameraInfo : public android::Parcelable { |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 43 | /** |
| 44 | * The direction that the camera faces to. It should be CAMERA_FACING_BACK |
| 45 | * or CAMERA_FACING_FRONT. |
| 46 | */ |
| 47 | int facing; |
| 48 | |
| 49 | /** |
| 50 | * The orientation of the camera image. The value is the angle that the |
| 51 | * camera image needs to be rotated clockwise so it shows correctly on the |
| 52 | * display in its natural orientation. It should be 0, 90, 180, or 270. |
| 53 | * |
| 54 | * For example, suppose a device has a naturally tall screen. The |
| 55 | * back-facing camera sensor is mounted in landscape. You are looking at |
| 56 | * the screen. If the top side of the camera sensor is aligned with the |
| 57 | * right edge of the screen in natural orientation, the value should be |
| 58 | * 90. If the top side of a front-facing camera sensor is aligned with the |
| 59 | * right of the screen, the value should be 270. |
| 60 | */ |
| 61 | int orientation; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 62 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 63 | virtual status_t writeToParcel(android::Parcel* parcel) const; |
| 64 | virtual status_t readFromParcel(const android::Parcel* parcel); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 65 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 68 | /** |
| 69 | * Basic status information about a camera device - its name and its current |
| 70 | * state. |
| 71 | */ |
| 72 | struct CameraStatus : public android::Parcelable { |
| 73 | /** |
| 74 | * The name of the camera device |
| 75 | */ |
| 76 | String8 cameraId; |
| 77 | |
| 78 | /** |
| 79 | * Its current status, one of the ICameraService::STATUS_* fields |
| 80 | */ |
| 81 | int32_t status; |
| 82 | |
| 83 | virtual status_t writeToParcel(android::Parcel* parcel) const; |
| 84 | virtual status_t readFromParcel(const android::Parcel* parcel); |
| 85 | |
| 86 | CameraStatus(String8 id, int32_t s) : cameraId(id), status(s) {} |
| 87 | CameraStatus() : status(ICameraServiceListener::STATUS_PRESENT) {} |
| 88 | }; |
| 89 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 90 | } // namespace hardware |
| 91 | |
| 92 | using hardware::CameraInfo; |
| 93 | |
| 94 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 95 | template <typename TCam> |
| 96 | struct CameraTraits { |
| 97 | }; |
| 98 | |
| 99 | template <typename TCam, typename TCamTraits = CameraTraits<TCam> > |
| 100 | class CameraBase : public IBinder::DeathRecipient |
| 101 | { |
| 102 | public: |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 103 | typedef typename TCamTraits::TCamListener TCamListener; |
| 104 | typedef typename TCamTraits::TCamUser TCamUser; |
| 105 | typedef typename TCamTraits::TCamCallbacks TCamCallbacks; |
| 106 | typedef typename TCamTraits::TCamConnectService TCamConnectService; |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 107 | |
| 108 | static sp<TCam> connect(int cameraId, |
| 109 | const String16& clientPackageName, |
Chien-Yu Chen | 98a668f | 2015-12-18 14:10:33 -0800 | [diff] [blame] | 110 | int clientUid, int clientPid); |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 111 | virtual void disconnect(); |
| 112 | |
| 113 | void setListener(const sp<TCamListener>& listener); |
| 114 | |
| 115 | static int getNumberOfCameras(); |
| 116 | |
| 117 | static status_t getCameraInfo(int cameraId, |
| 118 | /*out*/ |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 119 | struct hardware::CameraInfo* cameraInfo); |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 120 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 121 | sp<TCamUser> remote(); |
| 122 | |
| 123 | // Status is set to 'UNKNOWN_ERROR' after successful (re)connection |
| 124 | status_t getStatus(); |
| 125 | |
| 126 | protected: |
| 127 | CameraBase(int cameraId); |
| 128 | virtual ~CameraBase(); |
| 129 | |
| 130 | //////////////////////////////////////////////////////// |
| 131 | // TCamCallbacks implementation |
| 132 | //////////////////////////////////////////////////////// |
| 133 | virtual void notifyCallback(int32_t msgType, int32_t ext, |
| 134 | int32_t ext2); |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 135 | |
| 136 | //////////////////////////////////////////////////////// |
| 137 | // Common instance variables |
| 138 | //////////////////////////////////////////////////////// |
| 139 | Mutex mLock; |
| 140 | |
| 141 | virtual void binderDied(const wp<IBinder>& who); |
| 142 | |
| 143 | // helper function to obtain camera service handle |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 144 | static const sp<::android::hardware::ICameraService>& getCameraService(); |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 145 | |
| 146 | sp<TCamUser> mCamera; |
| 147 | status_t mStatus; |
| 148 | |
| 149 | sp<TCamListener> mListener; |
| 150 | |
| 151 | const int mCameraId; |
| 152 | |
Igor Murashkin | fa4cf9d | 2013-03-04 16:14:23 -0800 | [diff] [blame] | 153 | typedef CameraBase<TCam> CameraBaseT; |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | }; // namespace android |
| 157 | |
| 158 | #endif |