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