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