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