| 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 |     /** | 
 | 38 |      * Base binder interface (see ICamera/IProCameraUser for details) | 
 | 39 |      */ | 
 | 40 |     virtual status_t      connect(const sp<TCamCallbacks>& callbacks); | 
 | 41 |     virtual void          disconnect(); | 
 | 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, | 
 | 51 |                       int cameraId, | 
 | 52 |                       int cameraFacing, | 
 | 53 |                       int clientPid, | 
 | 54 |                       uid_t clientUid, | 
 | 55 |                       int servicePid); | 
 | 56 |     virtual ~Camera2ClientBase(); | 
 | 57 |  | 
 | 58 |     virtual status_t      initialize(camera_module_t *module); | 
 | 59 |     virtual status_t      dump(int fd, const Vector<String16>& args); | 
 | 60 |  | 
 | 61 |     /** | 
 | 62 |      * CameraDeviceBase::NotificationListener implementation | 
 | 63 |      */ | 
 | 64 |  | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 65 |     virtual void          notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode, | 
 | 66 |                                       const CaptureResultExtras& resultExtras); | 
| Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 67 |     virtual void          notifyIdle(); | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 68 |     virtual void          notifyShutter(const CaptureResultExtras& resultExtras, | 
 | 69 |                                         nsecs_t timestamp); | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 70 |     virtual void          notifyAutoFocus(uint8_t newState, int triggerId); | 
 | 71 |     virtual void          notifyAutoExposure(uint8_t newState, int triggerId); | 
 | 72 |     virtual void          notifyAutoWhitebalance(uint8_t newState, | 
 | 73 |                                                  int triggerId); | 
 | 74 |  | 
 | 75 |  | 
 | 76 |     int                   getCameraId() const; | 
 | 77 |     const sp<CameraDeviceBase>& | 
 | 78 |                           getCameraDevice(); | 
| Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 79 |     int                   getCameraDeviceVersion() const; | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 80 |     const sp<CameraService>& | 
 | 81 |                           getCameraService(); | 
 | 82 |  | 
 | 83 |     /** | 
 | 84 |      * Interface used by independent components of CameraClient2Base. | 
 | 85 |      */ | 
 | 86 |  | 
 | 87 |     // Simple class to ensure that access to TCamCallbacks is serialized | 
 | 88 |     // by requiring mRemoteCallbackLock to be locked before access to | 
 | 89 |     // mRemoteCallback is possible. | 
 | 90 |     class SharedCameraCallbacks { | 
 | 91 |       public: | 
 | 92 |         class Lock { | 
 | 93 |           public: | 
 | 94 |             Lock(SharedCameraCallbacks &client); | 
 | 95 |             ~Lock(); | 
 | 96 |             sp<TCamCallbacks> &mRemoteCallback; | 
 | 97 |           private: | 
 | 98 |             SharedCameraCallbacks &mSharedClient; | 
 | 99 |         }; | 
 | 100 |         SharedCameraCallbacks(const sp<TCamCallbacks>& client); | 
 | 101 |         SharedCameraCallbacks& operator=(const sp<TCamCallbacks>& client); | 
 | 102 |         void clear(); | 
 | 103 |       private: | 
 | 104 |         sp<TCamCallbacks> mRemoteCallback; | 
 | 105 |         mutable Mutex mRemoteCallbackLock; | 
 | 106 |     } mSharedCameraCallbacks; | 
 | 107 |  | 
 | 108 | protected: | 
 | 109 |  | 
| Eino-Ville Talvala | b9d2f33 | 2014-09-18 17:24:22 -0700 | [diff] [blame] | 110 |     // The PID provided in the constructor call | 
 | 111 |     pid_t mInitialClientPid; | 
 | 112 |  | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 113 |     virtual sp<IBinder> asBinderWrapper() { | 
 | 114 |         return IInterface::asBinder(); | 
 | 115 |     } | 
 | 116 |  | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 117 |     virtual status_t      dumpDevice(int fd, const Vector<String16>& args); | 
 | 118 |  | 
 | 119 |     /** Binder client interface-related private members */ | 
 | 120 |  | 
 | 121 |     // Mutex that must be locked by methods implementing the binder client | 
 | 122 |     // interface. Ensures serialization between incoming client calls. | 
 | 123 |     // All methods in this class hierarchy that append 'L' to the name assume | 
 | 124 |     // that mBinderSerializationLock is locked when they're called | 
 | 125 |     mutable Mutex         mBinderSerializationLock; | 
 | 126 |  | 
 | 127 |     /** CameraDeviceBase instance wrapping HAL2+ entry */ | 
 | 128 |  | 
| Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 129 |     const int mDeviceVersion; | 
| Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 130 |     sp<CameraDeviceBase>  mDevice; | 
 | 131 |  | 
 | 132 |     /** Utility members */ | 
 | 133 |  | 
 | 134 |     // Verify that caller is the owner of the camera | 
 | 135 |     status_t              checkPid(const char *checkLocation) const; | 
 | 136 |  | 
 | 137 |     virtual void          detachDevice(); | 
 | 138 | }; | 
 | 139 |  | 
 | 140 | }; // namespace android | 
 | 141 |  | 
 | 142 | #endif |