Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1 | /* |
Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 2 | * Copyright (C) 2008 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 | */ |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 16 | |
| 17 | #ifndef ANDROID_SERVERS_CAMERA_CAMERASERVICE_H |
| 18 | #define ANDROID_SERVERS_CAMERA_CAMERASERVICE_H |
| 19 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 20 | #include <utils/Vector.h> |
Ruben Brunk | b2119af | 2014-05-09 19:57:56 -0700 | [diff] [blame] | 21 | #include <utils/KeyedVector.h> |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 22 | #include <binder/AppOpsManager.h> |
Mathias Agopian | 5462fc9 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 23 | #include <binder/BinderService.h> |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 24 | #include <binder/IAppOpsCallback.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 25 | #include <camera/ICameraService.h> |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 26 | #include <hardware/camera.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 27 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 28 | #include <camera/ICamera.h> |
| 29 | #include <camera/ICameraClient.h> |
| 30 | #include <camera/IProCameraUser.h> |
| 31 | #include <camera/IProCameraCallbacks.h> |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 32 | #include <camera/camera2/ICameraDeviceUser.h> |
| 33 | #include <camera/camera2/ICameraDeviceCallbacks.h> |
Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 34 | #include <camera/VendorTagDescriptor.h> |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 35 | #include <camera/CaptureResult.h> |
Ruben Brunk | b2119af | 2014-05-09 19:57:56 -0700 | [diff] [blame] | 36 | #include <camera/CameraParameters.h> |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 37 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 38 | #include <camera/ICameraServiceListener.h> |
| 39 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 40 | /* This needs to be increased if we can have more cameras */ |
| 41 | #define MAX_CAMERAS 2 |
| 42 | |
| 43 | namespace android { |
| 44 | |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 45 | extern volatile int32_t gLogLevel; |
| 46 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 47 | class MemoryHeapBase; |
| 48 | class MediaPlayer; |
| 49 | |
Mathias Agopian | 5462fc9 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 50 | class CameraService : |
| 51 | public BinderService<CameraService>, |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 52 | public BnCameraService, |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 53 | public IBinder::DeathRecipient, |
| 54 | public camera_module_callbacks_t |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 55 | { |
Mathias Agopian | 5462fc9 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 56 | friend class BinderService<CameraService>; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 57 | public: |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 58 | class Client; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 59 | class BasicClient; |
| 60 | |
| 61 | // Implementation of BinderService<T> |
Mathias Agopian | 5462fc9 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 62 | static char const* getServiceName() { return "media.camera"; } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 63 | |
| 64 | CameraService(); |
| 65 | virtual ~CameraService(); |
| 66 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 67 | ///////////////////////////////////////////////////////////////////// |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 68 | // HAL Callbacks |
| 69 | virtual void onDeviceStatusChanged(int cameraId, |
| 70 | int newStatus); |
| 71 | |
| 72 | ///////////////////////////////////////////////////////////////////// |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 73 | // ICameraService |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 74 | virtual int32_t getNumberOfCameras(); |
| 75 | virtual status_t getCameraInfo(int cameraId, |
| 76 | struct CameraInfo* cameraInfo); |
Zhijun He | 2b59be8 | 2013-09-25 10:14:30 -0700 | [diff] [blame] | 77 | virtual status_t getCameraCharacteristics(int cameraId, |
| 78 | CameraMetadata* cameraInfo); |
Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 79 | virtual status_t getCameraVendorTagDescriptor(/*out*/ sp<VendorTagDescriptor>& desc); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 80 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 81 | virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId, |
| 82 | const String16& clientPackageName, int clientUid, |
| 83 | /*out*/ |
| 84 | sp<ICamera>& device); |
| 85 | |
Zhijun He | b10cdad | 2014-06-16 16:38:35 -0700 | [diff] [blame] | 86 | virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId, |
| 87 | int halVersion, const String16& clientPackageName, int clientUid, |
| 88 | /*out*/ |
| 89 | sp<ICamera>& device); |
| 90 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 91 | virtual status_t connectPro(const sp<IProCameraCallbacks>& cameraCb, |
| 92 | int cameraId, const String16& clientPackageName, int clientUid, |
| 93 | /*out*/ |
| 94 | sp<IProCameraUser>& device); |
| 95 | |
| 96 | virtual status_t connectDevice( |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 97 | const sp<ICameraDeviceCallbacks>& cameraCb, |
| 98 | int cameraId, |
| 99 | const String16& clientPackageName, |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 100 | int clientUid, |
| 101 | /*out*/ |
| 102 | sp<ICameraDeviceUser>& device); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 103 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 104 | virtual status_t addListener(const sp<ICameraServiceListener>& listener); |
| 105 | virtual status_t removeListener( |
| 106 | const sp<ICameraServiceListener>& listener); |
| 107 | |
Igor Murashkin | 65d14b9 | 2014-06-17 12:03:20 -0700 | [diff] [blame] | 108 | virtual status_t getLegacyParameters( |
| 109 | int cameraId, |
| 110 | /*out*/ |
| 111 | String16* parameters); |
| 112 | |
| 113 | // OK = supports api of that version, -EOPNOTSUPP = does not support |
| 114 | virtual status_t supportsCameraApi( |
| 115 | int cameraId, int apiVersion); |
| 116 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 117 | // Extra permissions checks |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 118 | virtual status_t onTransact(uint32_t code, const Parcel& data, |
| 119 | Parcel* reply, uint32_t flags); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 120 | |
| 121 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 122 | |
| 123 | ///////////////////////////////////////////////////////////////////// |
| 124 | // Client functionality |
| 125 | virtual void removeClientByRemote(const wp<IBinder>& remoteBinder); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 126 | |
| 127 | enum sound_kind { |
| 128 | SOUND_SHUTTER = 0, |
| 129 | SOUND_RECORDING = 1, |
| 130 | NUM_SOUNDS |
| 131 | }; |
| 132 | |
| 133 | void loadSound(); |
| 134 | void playSound(sound_kind kind); |
| 135 | void releaseSound(); |
| 136 | |
Igor Murashkin | 98e2472 | 2013-06-19 19:51:04 -0700 | [diff] [blame] | 137 | ///////////////////////////////////////////////////////////////////// |
| 138 | // CameraDeviceFactory functionality |
| 139 | int getDeviceVersion(int cameraId, int* facing = NULL); |
| 140 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 141 | |
| 142 | ///////////////////////////////////////////////////////////////////// |
| 143 | // CameraClient functionality |
| 144 | |
| 145 | // returns plain pointer of client. Note that mClientLock should be acquired to |
| 146 | // prevent the client from destruction. The result can be NULL. |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 147 | virtual BasicClient* getClientByIdUnsafe(int cameraId); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 148 | virtual Mutex* getClientLockById(int cameraId); |
| 149 | |
| 150 | class BasicClient : public virtual RefBase { |
| 151 | public: |
| 152 | virtual status_t initialize(camera_module_t *module) = 0; |
| 153 | |
| 154 | virtual void disconnect() = 0; |
| 155 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 156 | // because we can't virtually inherit IInterface, which breaks |
| 157 | // virtual inheritance |
| 158 | virtual sp<IBinder> asBinderWrapper() = 0; |
| 159 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 160 | // Return the remote callback binder object (e.g. IProCameraCallbacks) |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 161 | sp<IBinder> getRemote() { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 162 | return mRemoteBinder; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 163 | } |
| 164 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 165 | virtual status_t dump(int fd, const Vector<String16>& args) = 0; |
| 166 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 167 | protected: |
| 168 | BasicClient(const sp<CameraService>& cameraService, |
| 169 | const sp<IBinder>& remoteCallback, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 170 | const String16& clientPackageName, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 171 | int cameraId, |
| 172 | int cameraFacing, |
| 173 | int clientPid, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 174 | uid_t clientUid, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 175 | int servicePid); |
| 176 | |
| 177 | virtual ~BasicClient(); |
| 178 | |
| 179 | // the instance is in the middle of destruction. When this is set, |
| 180 | // the instance should not be accessed from callback. |
| 181 | // CameraService's mClientLock should be acquired to access this. |
| 182 | // - subclasses should set this to true in their destructors. |
| 183 | bool mDestructionStarted; |
| 184 | |
| 185 | // these are initialized in the constructor. |
| 186 | sp<CameraService> mCameraService; // immutable after constructor |
| 187 | int mCameraId; // immutable after constructor |
| 188 | int mCameraFacing; // immutable after constructor |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 189 | const String16 mClientPackageName; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 190 | pid_t mClientPid; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 191 | uid_t mClientUid; // immutable after constructor |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 192 | pid_t mServicePid; // immutable after constructor |
| 193 | |
| 194 | // - The app-side Binder interface to receive callbacks from us |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 195 | sp<IBinder> mRemoteBinder; // immutable after constructor |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 196 | |
| 197 | // permissions management |
| 198 | status_t startCameraOps(); |
| 199 | status_t finishCameraOps(); |
| 200 | |
| 201 | // Notify client about a fatal error |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 202 | virtual void notifyError( |
| 203 | ICameraDeviceCallbacks::CameraErrorCode errorCode, |
| 204 | const CaptureResultExtras& resultExtras) = 0; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 205 | private: |
| 206 | AppOpsManager mAppOpsManager; |
| 207 | |
| 208 | class OpsCallback : public BnAppOpsCallback { |
| 209 | public: |
| 210 | OpsCallback(wp<BasicClient> client); |
| 211 | virtual void opChanged(int32_t op, const String16& packageName); |
| 212 | |
| 213 | private: |
| 214 | wp<BasicClient> mClient; |
| 215 | |
| 216 | }; // class OpsCallback |
| 217 | |
| 218 | sp<OpsCallback> mOpsCallback; |
| 219 | // Track whether startCameraOps was called successfully, to avoid |
| 220 | // finishing what we didn't start. |
| 221 | bool mOpsActive; |
| 222 | |
| 223 | // IAppOpsCallback interface, indirected through opListener |
| 224 | virtual void opChanged(int32_t op, const String16& packageName); |
| 225 | }; // class BasicClient |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 226 | |
| 227 | class Client : public BnCamera, public BasicClient |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 228 | { |
| 229 | public: |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 230 | typedef ICameraClient TCamCallbacks; |
| 231 | |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 232 | // ICamera interface (see ICamera for details) |
| 233 | virtual void disconnect(); |
| 234 | virtual status_t connect(const sp<ICameraClient>& client) = 0; |
| 235 | virtual status_t lock() = 0; |
| 236 | virtual status_t unlock() = 0; |
Eino-Ville Talvala | 1ce7c34 | 2013-08-21 13:57:21 -0700 | [diff] [blame] | 237 | virtual status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)=0; |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 238 | virtual void setPreviewCallbackFlag(int flag) = 0; |
Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 239 | virtual status_t setPreviewCallbackTarget( |
| 240 | const sp<IGraphicBufferProducer>& callbackProducer) = 0; |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 241 | virtual status_t startPreview() = 0; |
| 242 | virtual void stopPreview() = 0; |
| 243 | virtual bool previewEnabled() = 0; |
| 244 | virtual status_t storeMetaDataInBuffers(bool enabled) = 0; |
| 245 | virtual status_t startRecording() = 0; |
| 246 | virtual void stopRecording() = 0; |
| 247 | virtual bool recordingEnabled() = 0; |
| 248 | virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0; |
| 249 | virtual status_t autoFocus() = 0; |
| 250 | virtual status_t cancelAutoFocus() = 0; |
| 251 | virtual status_t takePicture(int msgType) = 0; |
| 252 | virtual status_t setParameters(const String8& params) = 0; |
| 253 | virtual String8 getParameters() const = 0; |
| 254 | virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0; |
| 255 | |
| 256 | // Interface used by CameraService |
| 257 | Client(const sp<CameraService>& cameraService, |
| 258 | const sp<ICameraClient>& cameraClient, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 259 | const String16& clientPackageName, |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 260 | int cameraId, |
| 261 | int cameraFacing, |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 262 | int clientPid, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 263 | uid_t clientUid, |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 264 | int servicePid); |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 265 | ~Client(); |
| 266 | |
| 267 | // return our camera client |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 268 | const sp<ICameraClient>& getRemoteCallback() { |
| 269 | return mRemoteCallback; |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 272 | virtual sp<IBinder> asBinderWrapper() { |
| 273 | return asBinder(); |
| 274 | } |
| 275 | |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 276 | protected: |
| 277 | static Mutex* getClientLockFromCookie(void* user); |
| 278 | // convert client from cookie. Client lock should be acquired before getting Client. |
| 279 | static Client* getClientFromCookie(void* user); |
| 280 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 281 | virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode, |
| 282 | const CaptureResultExtras& resultExtras); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 283 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 284 | // Initialized in constructor |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 285 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 286 | // - The app-side Binder interface to receive callbacks from us |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 287 | sp<ICameraClient> mRemoteCallback; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 288 | |
| 289 | }; // class Client |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 290 | |
| 291 | class ProClient : public BnProCameraUser, public BasicClient { |
| 292 | public: |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 293 | typedef IProCameraCallbacks TCamCallbacks; |
| 294 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 295 | ProClient(const sp<CameraService>& cameraService, |
| 296 | const sp<IProCameraCallbacks>& remoteCallback, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 297 | const String16& clientPackageName, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 298 | int cameraId, |
| 299 | int cameraFacing, |
| 300 | int clientPid, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 301 | uid_t clientUid, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 302 | int servicePid); |
| 303 | |
| 304 | virtual ~ProClient(); |
| 305 | |
| 306 | const sp<IProCameraCallbacks>& getRemoteCallback() { |
| 307 | return mRemoteCallback; |
| 308 | } |
| 309 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 310 | /*** |
| 311 | IProCamera implementation |
| 312 | ***/ |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 313 | virtual status_t connect(const sp<IProCameraCallbacks>& callbacks) |
| 314 | = 0; |
| 315 | virtual status_t exclusiveTryLock() = 0; |
| 316 | virtual status_t exclusiveLock() = 0; |
| 317 | virtual status_t exclusiveUnlock() = 0; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 318 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 319 | virtual bool hasExclusiveLock() = 0; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 320 | |
| 321 | // Note that the callee gets a copy of the metadata. |
| 322 | virtual int submitRequest(camera_metadata_t* metadata, |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 323 | bool streaming = false) = 0; |
| 324 | virtual status_t cancelRequest(int requestId) = 0; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 325 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 326 | // Callbacks from camera service |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 327 | virtual void onExclusiveLockStolen() = 0; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 328 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 329 | protected: |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 330 | virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode, |
| 331 | const CaptureResultExtras& resultExtras); |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 332 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 333 | sp<IProCameraCallbacks> mRemoteCallback; |
| 334 | }; // class ProClient |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 335 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 336 | private: |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 337 | |
| 338 | // Delay-load the Camera HAL module |
| 339 | virtual void onFirstRef(); |
| 340 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 341 | // Step 1. Check if we can connect, before we acquire the service lock. |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 342 | status_t validateConnect(int cameraId, |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 343 | /*inout*/ |
| 344 | int& clientUid) const; |
| 345 | |
| 346 | // Step 2. Check if we can connect, after we acquire the service lock. |
| 347 | bool canConnectUnsafe(int cameraId, |
| 348 | const String16& clientPackageName, |
| 349 | const sp<IBinder>& remoteCallback, |
| 350 | /*out*/ |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 351 | sp<BasicClient> &client); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 352 | |
| 353 | // When connection is successful, initialize client and track its death |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 354 | status_t connectFinishUnsafe(const sp<BasicClient>& client, |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 355 | const sp<IBinder>& remoteCallback); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 356 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 357 | virtual sp<BasicClient> getClientByRemote(const wp<IBinder>& cameraClient); |
| 358 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 359 | Mutex mServiceLock; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 360 | // either a Client or CameraDeviceClient |
| 361 | wp<BasicClient> mClient[MAX_CAMERAS]; // protected by mServiceLock |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 362 | Mutex mClientLock[MAX_CAMERAS]; // prevent Client destruction inside callbacks |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 363 | int mNumberOfCameras; |
| 364 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 365 | typedef wp<ProClient> weak_pro_client_ptr; |
| 366 | Vector<weak_pro_client_ptr> mProClientList[MAX_CAMERAS]; |
| 367 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 368 | // needs to be called with mServiceLock held |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 369 | sp<BasicClient> findClientUnsafe(const wp<IBinder>& cameraClient, int& outIndex); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 370 | sp<ProClient> findProClientUnsafe( |
| 371 | const wp<IBinder>& cameraCallbacksRemote); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 372 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 373 | // atomics to record whether the hardware is allocated to some client. |
| 374 | volatile int32_t mBusy[MAX_CAMERAS]; |
| 375 | void setCameraBusy(int cameraId); |
| 376 | void setCameraFree(int cameraId); |
| 377 | |
| 378 | // sounds |
Chih-Chung Chang | ff4f55c | 2011-10-17 19:03:12 +0800 | [diff] [blame] | 379 | MediaPlayer* newMediaPlayer(const char *file); |
| 380 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 381 | Mutex mSoundLock; |
| 382 | sp<MediaPlayer> mSoundPlayer[NUM_SOUNDS]; |
| 383 | int mSoundRef; // reference count (release all MediaPlayer when 0) |
| 384 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 385 | camera_module_t *mModule; |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 386 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 387 | Vector<sp<ICameraServiceListener> > |
| 388 | mListenerList; |
| 389 | |
| 390 | // guard only mStatusList and the broadcasting of ICameraServiceListener |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 391 | mutable Mutex mStatusMutex; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 392 | ICameraServiceListener::Status |
| 393 | mStatusList[MAX_CAMERAS]; |
| 394 | |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 395 | // Read the current status (locks mStatusMutex) |
| 396 | ICameraServiceListener::Status |
| 397 | getStatus(int cameraId) const; |
| 398 | |
Igor Murashkin | 93747b9 | 2013-05-01 15:42:20 -0700 | [diff] [blame] | 399 | typedef Vector<ICameraServiceListener::Status> StatusVector; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 400 | // Broadcast the new status if it changed (locks the service mutex) |
| 401 | void updateStatus( |
| 402 | ICameraServiceListener::Status status, |
Igor Murashkin | 93747b9 | 2013-05-01 15:42:20 -0700 | [diff] [blame] | 403 | int32_t cameraId, |
| 404 | const StatusVector *rejectSourceStates = NULL); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 405 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 406 | // IBinder::DeathRecipient implementation |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 407 | virtual void binderDied(const wp<IBinder> &who); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 408 | |
| 409 | // Helpers |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 410 | |
| 411 | bool isValidCameraId(int cameraId); |
Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 412 | |
| 413 | bool setUpVendorTags(); |
Ruben Brunk | b2119af | 2014-05-09 19:57:56 -0700 | [diff] [blame] | 414 | |
| 415 | /** |
| 416 | * A mapping of camera ids to CameraParameters returned by that camera device. |
| 417 | * |
| 418 | * This cache is used to generate CameraCharacteristic metadata when using |
| 419 | * the HAL1 shim. |
| 420 | */ |
| 421 | KeyedVector<int, CameraParameters> mShimParams; |
| 422 | |
| 423 | /** |
| 424 | * Initialize and cache the metadata used by the HAL1 shim for a given cameraId. |
| 425 | * |
| 426 | * Returns OK on success, or a negative error code. |
| 427 | */ |
| 428 | status_t initializeShimMetadata(int cameraId); |
| 429 | |
| 430 | /** |
Igor Murashkin | 65d14b9 | 2014-06-17 12:03:20 -0700 | [diff] [blame] | 431 | * Get the cached CameraParameters for the camera. If they haven't been |
| 432 | * cached yet, then initialize them for the first time. |
| 433 | * |
| 434 | * Returns OK on success, or a negative error code. |
| 435 | */ |
| 436 | status_t getLegacyParametersLazy(int cameraId, /*out*/CameraParameters* parameters); |
| 437 | |
| 438 | /** |
Ruben Brunk | b2119af | 2014-05-09 19:57:56 -0700 | [diff] [blame] | 439 | * Generate the CameraCharacteristics metadata required by the Camera2 API |
| 440 | * from the available HAL1 CameraParameters and CameraInfo. |
| 441 | * |
| 442 | * Returns OK on success, or a negative error code. |
| 443 | */ |
| 444 | status_t generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo); |
| 445 | |
| 446 | /** |
| 447 | * Connect a new camera client. This should only be used while holding the |
| 448 | * mutex for mServiceLock. |
| 449 | * |
| 450 | * Returns OK on success, or a negative error code. |
| 451 | */ |
| 452 | status_t connectHelperLocked(const sp<ICameraClient>& cameraClient, |
| 453 | int cameraId, |
| 454 | const String16& clientPackageName, |
| 455 | int clientUid, |
| 456 | int callingPid, |
| 457 | /*out*/ |
Zhijun He | b10cdad | 2014-06-16 16:38:35 -0700 | [diff] [blame] | 458 | sp<Client>& client, |
| 459 | int halVersion = CAMERA_HAL_API_VERSION_UNSPECIFIED); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 460 | }; |
| 461 | |
| 462 | } // namespace android |
| 463 | |
| 464 | #endif |