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 | |
| 20 | #include <utils/Mutex.h> |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 21 | |
| 22 | struct camera_frame_metadata; |
| 23 | |
| 24 | namespace android { |
| 25 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 26 | namespace hardware { |
| 27 | |
| 28 | |
| 29 | class ICameraService; |
| 30 | class ICameraServiceListener; |
| 31 | |
| 32 | struct CameraInfo : public android::Parcelable { |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 33 | /** |
| 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 Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 52 | |
| 53 | virtual status_t writeToParcel(Parcel* parcel) const; |
| 54 | virtual status_t readFromParcel(const Parcel* parcel); |
| 55 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 56 | }; |
| 57 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 58 | } // namespace hardware |
| 59 | |
| 60 | using hardware::CameraInfo; |
| 61 | |
| 62 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 63 | template <typename TCam> |
| 64 | struct CameraTraits { |
| 65 | }; |
| 66 | |
| 67 | template <typename TCam, typename TCamTraits = CameraTraits<TCam> > |
| 68 | class CameraBase : public IBinder::DeathRecipient |
| 69 | { |
| 70 | public: |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 71 | typedef typename TCamTraits::TCamListener TCamListener; |
| 72 | typedef typename TCamTraits::TCamUser TCamUser; |
| 73 | typedef typename TCamTraits::TCamCallbacks TCamCallbacks; |
| 74 | typedef typename TCamTraits::TCamConnectService TCamConnectService; |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 75 | |
| 76 | static sp<TCam> connect(int cameraId, |
| 77 | const String16& clientPackageName, |
Chien-Yu Chen | 98a668f | 2015-12-18 14:10:33 -0800 | [diff] [blame] | 78 | int clientUid, int clientPid); |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 79 | 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 Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 87 | struct hardware::CameraInfo* cameraInfo); |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 88 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 89 | static status_t addServiceListener( |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 90 | const sp<::android::hardware::ICameraServiceListener>& listener); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 91 | |
| 92 | static status_t removeServiceListener( |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 93 | const sp<::android::hardware::ICameraServiceListener>& listener); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 94 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 95 | sp<TCamUser> remote(); |
| 96 | |
| 97 | // Status is set to 'UNKNOWN_ERROR' after successful (re)connection |
| 98 | status_t getStatus(); |
| 99 | |
| 100 | protected: |
| 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 Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 109 | |
| 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 Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 118 | static const sp<::android::hardware::ICameraService>& getCameraService(); |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 119 | |
| 120 | sp<TCamUser> mCamera; |
| 121 | status_t mStatus; |
| 122 | |
| 123 | sp<TCamListener> mListener; |
| 124 | |
| 125 | const int mCameraId; |
| 126 | |
Igor Murashkin | fa4cf9d | 2013-03-04 16:14:23 -0800 | [diff] [blame] | 127 | typedef CameraBase<TCam> CameraBaseT; |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | }; // namespace android |
| 131 | |
| 132 | #endif |