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; |
| 193 | virtual status_t startPreview() = 0; |
| 194 | virtual void stopPreview() = 0; |
| 195 | virtual bool previewEnabled() = 0; |
| 196 | virtual status_t storeMetaDataInBuffers(bool enabled) = 0; |
| 197 | virtual status_t startRecording() = 0; |
| 198 | virtual void stopRecording() = 0; |
| 199 | virtual bool recordingEnabled() = 0; |
| 200 | virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0; |
| 201 | virtual status_t autoFocus() = 0; |
| 202 | virtual status_t cancelAutoFocus() = 0; |
| 203 | virtual status_t takePicture(int msgType) = 0; |
| 204 | virtual status_t setParameters(const String8& params) = 0; |
| 205 | virtual String8 getParameters() const = 0; |
| 206 | virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0; |
| 207 | |
| 208 | // Interface used by CameraService |
| 209 | Client(const sp<CameraService>& cameraService, |
| 210 | const sp<ICameraClient>& cameraClient, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 211 | const String16& clientPackageName, |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 212 | int cameraId, |
| 213 | int cameraFacing, |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 214 | int clientPid, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 215 | uid_t clientUid, |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 216 | int servicePid); |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 217 | ~Client(); |
| 218 | |
| 219 | // return our camera client |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 220 | const sp<ICameraClient>& getRemoteCallback() { |
| 221 | return mRemoteCallback; |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 224 | protected: |
| 225 | static Mutex* getClientLockFromCookie(void* user); |
| 226 | // convert client from cookie. Client lock should be acquired before getting Client. |
| 227 | static Client* getClientFromCookie(void* user); |
| 228 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 229 | virtual void notifyError(); |
| 230 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 231 | // Initialized in constructor |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 232 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 233 | // - The app-side Binder interface to receive callbacks from us |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 234 | sp<ICameraClient> mRemoteCallback; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 235 | |
| 236 | }; // class Client |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 237 | |
| 238 | class ProClient : public BnProCameraUser, public BasicClient { |
| 239 | public: |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 240 | typedef IProCameraCallbacks TCamCallbacks; |
| 241 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 242 | ProClient(const sp<CameraService>& cameraService, |
| 243 | const sp<IProCameraCallbacks>& remoteCallback, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 244 | const String16& clientPackageName, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 245 | int cameraId, |
| 246 | int cameraFacing, |
| 247 | int clientPid, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 248 | uid_t clientUid, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 249 | int servicePid); |
| 250 | |
| 251 | virtual ~ProClient(); |
| 252 | |
| 253 | const sp<IProCameraCallbacks>& getRemoteCallback() { |
| 254 | return mRemoteCallback; |
| 255 | } |
| 256 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 257 | /*** |
| 258 | IProCamera implementation |
| 259 | ***/ |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 260 | virtual status_t connect(const sp<IProCameraCallbacks>& callbacks) |
| 261 | = 0; |
| 262 | virtual status_t exclusiveTryLock() = 0; |
| 263 | virtual status_t exclusiveLock() = 0; |
| 264 | virtual status_t exclusiveUnlock() = 0; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 265 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 266 | virtual bool hasExclusiveLock() = 0; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 267 | |
| 268 | // Note that the callee gets a copy of the metadata. |
| 269 | virtual int submitRequest(camera_metadata_t* metadata, |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 270 | bool streaming = false) = 0; |
| 271 | virtual status_t cancelRequest(int requestId) = 0; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 272 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 273 | // Callbacks from camera service |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 274 | virtual void onExclusiveLockStolen() = 0; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 275 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 276 | protected: |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 277 | virtual void notifyError(); |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 278 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 279 | sp<IProCameraCallbacks> mRemoteCallback; |
| 280 | }; // class ProClient |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 281 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 282 | private: |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 283 | |
| 284 | // Delay-load the Camera HAL module |
| 285 | virtual void onFirstRef(); |
| 286 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 287 | // Step 1. Check if we can connect, before we acquire the service lock. |
| 288 | bool validateConnect(int cameraId, |
| 289 | /*inout*/ |
| 290 | int& clientUid) const; |
| 291 | |
| 292 | // Step 2. Check if we can connect, after we acquire the service lock. |
| 293 | bool canConnectUnsafe(int cameraId, |
| 294 | const String16& clientPackageName, |
| 295 | const sp<IBinder>& remoteCallback, |
| 296 | /*out*/ |
| 297 | sp<Client> &client); |
| 298 | |
| 299 | // When connection is successful, initialize client and track its death |
| 300 | bool connectFinishUnsafe(const sp<BasicClient>& client, |
| 301 | const sp<IBinder>& clientBinder); |
| 302 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 303 | virtual sp<BasicClient> getClientByRemote(const wp<IBinder>& cameraClient); |
| 304 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 305 | Mutex mServiceLock; |
| 306 | wp<Client> mClient[MAX_CAMERAS]; // protected by mServiceLock |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 307 | Mutex mClientLock[MAX_CAMERAS]; // prevent Client destruction inside callbacks |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 308 | int mNumberOfCameras; |
| 309 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 310 | typedef wp<ProClient> weak_pro_client_ptr; |
| 311 | Vector<weak_pro_client_ptr> mProClientList[MAX_CAMERAS]; |
| 312 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 313 | // needs to be called with mServiceLock held |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 314 | sp<Client> findClientUnsafe(const wp<IBinder>& cameraClient, int& outIndex); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 315 | sp<ProClient> findProClientUnsafe( |
| 316 | const wp<IBinder>& cameraCallbacksRemote); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 317 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 318 | // atomics to record whether the hardware is allocated to some client. |
| 319 | volatile int32_t mBusy[MAX_CAMERAS]; |
| 320 | void setCameraBusy(int cameraId); |
| 321 | void setCameraFree(int cameraId); |
| 322 | |
| 323 | // sounds |
Chih-Chung Chang | ff4f55c | 2011-10-17 19:03:12 +0800 | [diff] [blame] | 324 | MediaPlayer* newMediaPlayer(const char *file); |
| 325 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 326 | Mutex mSoundLock; |
| 327 | sp<MediaPlayer> mSoundPlayer[NUM_SOUNDS]; |
| 328 | int mSoundRef; // reference count (release all MediaPlayer when 0) |
| 329 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 330 | camera_module_t *mModule; |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 331 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 332 | Vector<sp<ICameraServiceListener> > |
| 333 | mListenerList; |
| 334 | |
| 335 | // guard only mStatusList and the broadcasting of ICameraServiceListener |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 336 | mutable Mutex mStatusMutex; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 337 | ICameraServiceListener::Status |
| 338 | mStatusList[MAX_CAMERAS]; |
| 339 | |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 340 | // Read the current status (locks mStatusMutex) |
| 341 | ICameraServiceListener::Status |
| 342 | getStatus(int cameraId) const; |
| 343 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 344 | // Broadcast the new status if it changed (locks the service mutex) |
| 345 | void updateStatus( |
| 346 | ICameraServiceListener::Status status, |
| 347 | int32_t cameraId); |
| 348 | // Call this one when the service mutex is already held (idempotent) |
| 349 | void updateStatusUnsafe( |
| 350 | ICameraServiceListener::Status status, |
| 351 | int32_t cameraId); |
| 352 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 353 | // IBinder::DeathRecipient implementation |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 354 | virtual void binderDied(const wp<IBinder> &who); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 355 | |
| 356 | // Helpers |
| 357 | int getDeviceVersion(int cameraId, int* facing); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 358 | |
| 359 | bool isValidCameraId(int cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 360 | }; |
| 361 | |
| 362 | } // namespace android |
| 363 | |
| 364 | #endif |