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