Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -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_SERVERS_CAMERA_CAMERA2CLIENT_BASE_H |
| 18 | #define ANDROID_SERVERS_CAMERA_CAMERA2CLIENT_BASE_H |
| 19 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 20 | #include "common/CameraDeviceBase.h" |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 21 | #include "camera/CaptureResult.h" |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | class IMemory; |
| 26 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 27 | class CameraService; |
| 28 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 29 | template <typename TClientBase> |
| 30 | class Camera2ClientBase : |
| 31 | public TClientBase, |
| 32 | public CameraDeviceBase::NotificationListener |
| 33 | { |
| 34 | public: |
| 35 | typedef typename TClientBase::TCamCallbacks TCamCallbacks; |
| 36 | |
| 37 | /** |
Ruben Brunk | 9efdf95 | 2015-03-18 23:11:57 -0700 | [diff] [blame] | 38 | * Base binder interface (see ICamera/ICameraDeviceUser for details) |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 39 | */ |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 40 | virtual status_t connect(const sp<TCamCallbacks>& callbacks); |
| 41 | virtual binder::Status disconnect(); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Interface used by CameraService |
| 45 | */ |
| 46 | |
| 47 | // TODO: too many params, move into a ClientArgs<T> |
| 48 | Camera2ClientBase(const sp<CameraService>& cameraService, |
| 49 | const sp<TCamCallbacks>& remoteCallback, |
| 50 | const String16& clientPackageName, |
Philip P. Moltmann | 9e648f6 | 2019-11-04 12:52:45 -0800 | [diff] [blame] | 51 | const std::unique_ptr<String16>& clientFeatureId, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 52 | const String8& cameraId, |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 53 | int api1CameraId, |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 54 | int cameraFacing, |
| 55 | int clientPid, |
| 56 | uid_t clientUid, |
| 57 | int servicePid); |
| 58 | virtual ~Camera2ClientBase(); |
| 59 | |
Emilian Peev | bd8c503 | 2018-02-14 23:05:40 +0000 | [diff] [blame] | 60 | virtual status_t initialize(sp<CameraProviderManager> manager, const String8& monitorTags); |
Eino-Ville Talvala | c400396 | 2016-01-13 10:07:04 -0800 | [diff] [blame] | 61 | virtual status_t dumpClient(int fd, const Vector<String16>& args); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * CameraDeviceBase::NotificationListener implementation |
| 65 | */ |
| 66 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 67 | virtual void notifyError(int32_t errorCode, |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 68 | const CaptureResultExtras& resultExtras); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 69 | virtual void notifyIdle(); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 70 | virtual void notifyShutter(const CaptureResultExtras& resultExtras, |
| 71 | nsecs_t timestamp); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 72 | virtual void notifyAutoFocus(uint8_t newState, int triggerId); |
| 73 | virtual void notifyAutoExposure(uint8_t newState, int triggerId); |
| 74 | virtual void notifyAutoWhitebalance(uint8_t newState, |
| 75 | int triggerId); |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 76 | virtual void notifyPrepared(int streamId); |
Shuzhen Wang | 9d06601 | 2016-09-30 11:30:20 -0700 | [diff] [blame] | 77 | virtual void notifyRequestQueueEmpty(); |
Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 78 | virtual void notifyRepeatingRequestError(long lastFrameNumber); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 79 | |
| 80 | int getCameraId() const; |
| 81 | const sp<CameraDeviceBase>& |
| 82 | getCameraDevice(); |
Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 83 | int getCameraDeviceVersion() const; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 84 | const sp<CameraService>& |
| 85 | getCameraService(); |
| 86 | |
| 87 | /** |
| 88 | * Interface used by independent components of CameraClient2Base. |
| 89 | */ |
| 90 | |
| 91 | // Simple class to ensure that access to TCamCallbacks is serialized |
| 92 | // by requiring mRemoteCallbackLock to be locked before access to |
| 93 | // mRemoteCallback is possible. |
| 94 | class SharedCameraCallbacks { |
| 95 | public: |
| 96 | class Lock { |
| 97 | public: |
Chih-Hung Hsieh | 8b0b971 | 2016-08-09 14:25:53 -0700 | [diff] [blame] | 98 | explicit Lock(SharedCameraCallbacks &client); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 99 | ~Lock(); |
| 100 | sp<TCamCallbacks> &mRemoteCallback; |
| 101 | private: |
| 102 | SharedCameraCallbacks &mSharedClient; |
| 103 | }; |
Chih-Hung Hsieh | 8b0b971 | 2016-08-09 14:25:53 -0700 | [diff] [blame] | 104 | explicit SharedCameraCallbacks(const sp<TCamCallbacks>& client); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 105 | SharedCameraCallbacks& operator=(const sp<TCamCallbacks>& client); |
| 106 | void clear(); |
| 107 | private: |
| 108 | sp<TCamCallbacks> mRemoteCallback; |
| 109 | mutable Mutex mRemoteCallbackLock; |
| 110 | } mSharedCameraCallbacks; |
| 111 | |
| 112 | protected: |
| 113 | |
Eino-Ville Talvala | b9d2f33 | 2014-09-18 17:24:22 -0700 | [diff] [blame] | 114 | // The PID provided in the constructor call |
| 115 | pid_t mInitialClientPid; |
| 116 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 117 | virtual sp<IBinder> asBinderWrapper() { |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 118 | return IInterface::asBinder(this); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 121 | virtual status_t dumpDevice(int fd, const Vector<String16>& args); |
| 122 | |
| 123 | /** Binder client interface-related private members */ |
| 124 | |
| 125 | // Mutex that must be locked by methods implementing the binder client |
| 126 | // interface. Ensures serialization between incoming client calls. |
| 127 | // All methods in this class hierarchy that append 'L' to the name assume |
| 128 | // that mBinderSerializationLock is locked when they're called |
| 129 | mutable Mutex mBinderSerializationLock; |
| 130 | |
Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 131 | /** CameraDeviceBase instance wrapping HAL3+ entry */ |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 132 | |
Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 133 | const int mDeviceVersion; |
Yin-Chia Yeh | c524813 | 2018-08-15 12:19:20 -0700 | [diff] [blame] | 134 | |
| 135 | // Set to const to avoid mDevice being updated (update of sp<> is racy) during |
| 136 | // dumpDevice (which is important to be lock free for debugging purpose) |
| 137 | const sp<CameraDeviceBase> mDevice; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 138 | |
| 139 | /** Utility members */ |
| 140 | |
| 141 | // Verify that caller is the owner of the camera |
| 142 | status_t checkPid(const char *checkLocation) const; |
| 143 | |
| 144 | virtual void detachDevice(); |
Eino-Ville Talvala | 412fe56 | 2015-08-20 17:08:32 -0700 | [diff] [blame] | 145 | |
| 146 | bool mDeviceActive; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 147 | |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 148 | const int mApi1CameraId; // -1 if client is API2 |
| 149 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 150 | private: |
| 151 | template<typename TProviderPtr> |
Emilian Peev | bd8c503 | 2018-02-14 23:05:40 +0000 | [diff] [blame] | 152 | status_t initializeImpl(TProviderPtr providerPtr, const String8& monitorTags); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | }; // namespace android |
| 156 | |
| 157 | #endif |