blob: 8a3db08a132ea4ecde1d4f3554c014a14f0656a9 [file] [log] [blame]
Mathias Agopian65ab4712010-07-14 17:59:35 -07001/*
Ruben Brunkd1176ef2014-02-21 10:51:38 -08002 * 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 Agopian65ab4712010-07-14 17:59:35 -070016
17#ifndef ANDROID_SERVERS_CAMERA_CAMERASERVICE_H
18#define ANDROID_SERVERS_CAMERA_CAMERASERVICE_H
19
Igor Murashkin634a5152013-02-20 17:15:11 -080020#include <utils/Vector.h>
Ruben Brunkb2119af2014-05-09 19:57:56 -070021#include <utils/KeyedVector.h>
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080022#include <binder/AppOpsManager.h>
Mathias Agopian5462fc92010-07-14 18:41:18 -070023#include <binder/BinderService.h>
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080024#include <binder/IAppOpsCallback.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070025#include <camera/ICameraService.h>
Iliyan Malchev8951a972011-04-14 16:55:59 -070026#include <hardware/camera.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070027
Igor Murashkinc073ba52013-02-26 14:32:34 -080028#include <camera/ICamera.h>
29#include <camera/ICameraClient.h>
30#include <camera/IProCameraUser.h>
31#include <camera/IProCameraCallbacks.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070032#include <camera/camera2/ICameraDeviceUser.h>
33#include <camera/camera2/ICameraDeviceCallbacks.h>
Ruben Brunkd1176ef2014-02-21 10:51:38 -080034#include <camera/VendorTagDescriptor.h>
Jianing Weicb0652e2014-03-12 18:29:36 -070035#include <camera/CaptureResult.h>
Ruben Brunkb2119af2014-05-09 19:57:56 -070036#include <camera/CameraParameters.h>
Igor Murashkinc073ba52013-02-26 14:32:34 -080037
Igor Murashkinbfc99152013-02-27 12:55:20 -080038#include <camera/ICameraServiceListener.h>
39
Mathias Agopian65ab4712010-07-14 17:59:35 -070040/* This needs to be increased if we can have more cameras */
41#define MAX_CAMERAS 2
42
43namespace android {
44
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -070045extern volatile int32_t gLogLevel;
46
Mathias Agopian65ab4712010-07-14 17:59:35 -070047class MemoryHeapBase;
48class MediaPlayer;
49
Mathias Agopian5462fc92010-07-14 18:41:18 -070050class CameraService :
51 public BinderService<CameraService>,
Igor Murashkinecf17e82012-10-02 16:05:11 -070052 public BnCameraService,
Igor Murashkincba2c162013-03-20 15:56:31 -070053 public IBinder::DeathRecipient,
54 public camera_module_callbacks_t
Mathias Agopian65ab4712010-07-14 17:59:35 -070055{
Mathias Agopian5462fc92010-07-14 18:41:18 -070056 friend class BinderService<CameraService>;
Mathias Agopian65ab4712010-07-14 17:59:35 -070057public:
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -070058 class Client;
Igor Murashkin634a5152013-02-20 17:15:11 -080059 class BasicClient;
60
Eino-Ville Talvalac9ab2b02016-01-13 10:07:04 -080061 // Event log ID
62 static const int SN_EVENT_LOG_ID = 0x534e4554;
63
Igor Murashkin634a5152013-02-20 17:15:11 -080064 // Implementation of BinderService<T>
Mathias Agopian5462fc92010-07-14 18:41:18 -070065 static char const* getServiceName() { return "media.camera"; }
Mathias Agopian65ab4712010-07-14 17:59:35 -070066
67 CameraService();
68 virtual ~CameraService();
69
Igor Murashkin634a5152013-02-20 17:15:11 -080070 /////////////////////////////////////////////////////////////////////
Igor Murashkincba2c162013-03-20 15:56:31 -070071 // HAL Callbacks
72 virtual void onDeviceStatusChanged(int cameraId,
73 int newStatus);
74
75 /////////////////////////////////////////////////////////////////////
Igor Murashkin634a5152013-02-20 17:15:11 -080076 // ICameraService
Mathias Agopian65ab4712010-07-14 17:59:35 -070077 virtual int32_t getNumberOfCameras();
78 virtual status_t getCameraInfo(int cameraId,
79 struct CameraInfo* cameraInfo);
Zhijun He2b59be82013-09-25 10:14:30 -070080 virtual status_t getCameraCharacteristics(int cameraId,
81 CameraMetadata* cameraInfo);
Ruben Brunkd1176ef2014-02-21 10:51:38 -080082 virtual status_t getCameraVendorTagDescriptor(/*out*/ sp<VendorTagDescriptor>& desc);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080083
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070084 virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId,
85 const String16& clientPackageName, int clientUid,
86 /*out*/
87 sp<ICamera>& device);
88
Zhijun Heb10cdad2014-06-16 16:38:35 -070089 virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId,
90 int halVersion, const String16& clientPackageName, int clientUid,
91 /*out*/
92 sp<ICamera>& device);
93
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070094 virtual status_t connectPro(const sp<IProCameraCallbacks>& cameraCb,
95 int cameraId, const String16& clientPackageName, int clientUid,
96 /*out*/
97 sp<IProCameraUser>& device);
98
99 virtual status_t connectDevice(
Igor Murashkine7ee7632013-06-11 18:10:18 -0700100 const sp<ICameraDeviceCallbacks>& cameraCb,
101 int cameraId,
102 const String16& clientPackageName,
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700103 int clientUid,
104 /*out*/
105 sp<ICameraDeviceUser>& device);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700106
Igor Murashkinbfc99152013-02-27 12:55:20 -0800107 virtual status_t addListener(const sp<ICameraServiceListener>& listener);
108 virtual status_t removeListener(
109 const sp<ICameraServiceListener>& listener);
110
Igor Murashkin65d14b92014-06-17 12:03:20 -0700111 virtual status_t getLegacyParameters(
112 int cameraId,
113 /*out*/
114 String16* parameters);
115
116 // OK = supports api of that version, -EOPNOTSUPP = does not support
117 virtual status_t supportsCameraApi(
118 int cameraId, int apiVersion);
119
Igor Murashkin634a5152013-02-20 17:15:11 -0800120 // Extra permissions checks
Mathias Agopian65ab4712010-07-14 17:59:35 -0700121 virtual status_t onTransact(uint32_t code, const Parcel& data,
122 Parcel* reply, uint32_t flags);
Igor Murashkin634a5152013-02-20 17:15:11 -0800123
124 virtual status_t dump(int fd, const Vector<String16>& args);
125
126 /////////////////////////////////////////////////////////////////////
127 // Client functionality
128 virtual void removeClientByRemote(const wp<IBinder>& remoteBinder);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700129
130 enum sound_kind {
131 SOUND_SHUTTER = 0,
132 SOUND_RECORDING = 1,
133 NUM_SOUNDS
134 };
135
136 void loadSound();
137 void playSound(sound_kind kind);
138 void releaseSound();
139
Igor Murashkin98e24722013-06-19 19:51:04 -0700140 /////////////////////////////////////////////////////////////////////
141 // CameraDeviceFactory functionality
142 int getDeviceVersion(int cameraId, int* facing = NULL);
143
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700144 /////////////////////////////////////////////////////////////////////
145 // Shared utilities
146 static status_t filterOpenErrorCode(status_t err);
147 static status_t filterGetInfoErrorCode(status_t err);
Igor Murashkin634a5152013-02-20 17:15:11 -0800148
149 /////////////////////////////////////////////////////////////////////
150 // CameraClient functionality
151
152 // returns plain pointer of client. Note that mClientLock should be acquired to
153 // prevent the client from destruction. The result can be NULL.
Igor Murashkine7ee7632013-06-11 18:10:18 -0700154 virtual BasicClient* getClientByIdUnsafe(int cameraId);
Igor Murashkin634a5152013-02-20 17:15:11 -0800155 virtual Mutex* getClientLockById(int cameraId);
156
157 class BasicClient : public virtual RefBase {
158 public:
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700159 virtual status_t initialize(camera_module_t *module) = 0;
160 virtual void disconnect();
Igor Murashkin634a5152013-02-20 17:15:11 -0800161
Igor Murashkine7ee7632013-06-11 18:10:18 -0700162 // because we can't virtually inherit IInterface, which breaks
163 // virtual inheritance
164 virtual sp<IBinder> asBinderWrapper() = 0;
165
Igor Murashkine6800ce2013-03-04 17:25:57 -0800166 // Return the remote callback binder object (e.g. IProCameraCallbacks)
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700167 sp<IBinder> getRemote() {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800168 return mRemoteBinder;
Igor Murashkin634a5152013-02-20 17:15:11 -0800169 }
170
Eino-Ville Talvalac9ab2b02016-01-13 10:07:04 -0800171 // Disallows dumping over binder interface
172 virtual status_t dump(int fd, const Vector<String16>& args);
173 // Internal dump method to be called by CameraService
174 virtual status_t dumpClient(int fd, const Vector<String16>& args) = 0;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700175
Igor Murashkin634a5152013-02-20 17:15:11 -0800176 protected:
177 BasicClient(const sp<CameraService>& cameraService,
178 const sp<IBinder>& remoteCallback,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800179 const String16& clientPackageName,
Igor Murashkin634a5152013-02-20 17:15:11 -0800180 int cameraId,
181 int cameraFacing,
182 int clientPid,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800183 uid_t clientUid,
Igor Murashkin634a5152013-02-20 17:15:11 -0800184 int servicePid);
185
186 virtual ~BasicClient();
187
188 // the instance is in the middle of destruction. When this is set,
189 // the instance should not be accessed from callback.
190 // CameraService's mClientLock should be acquired to access this.
191 // - subclasses should set this to true in their destructors.
192 bool mDestructionStarted;
193
194 // these are initialized in the constructor.
195 sp<CameraService> mCameraService; // immutable after constructor
196 int mCameraId; // immutable after constructor
197 int mCameraFacing; // immutable after constructor
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800198 const String16 mClientPackageName;
Igor Murashkin634a5152013-02-20 17:15:11 -0800199 pid_t mClientPid;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800200 uid_t mClientUid; // immutable after constructor
Igor Murashkin634a5152013-02-20 17:15:11 -0800201 pid_t mServicePid; // immutable after constructor
202
203 // - The app-side Binder interface to receive callbacks from us
Igor Murashkine7ee7632013-06-11 18:10:18 -0700204 sp<IBinder> mRemoteBinder; // immutable after constructor
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800205
206 // permissions management
207 status_t startCameraOps();
208 status_t finishCameraOps();
209
210 // Notify client about a fatal error
Jianing Weicb0652e2014-03-12 18:29:36 -0700211 virtual void notifyError(
212 ICameraDeviceCallbacks::CameraErrorCode errorCode,
213 const CaptureResultExtras& resultExtras) = 0;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800214 private:
215 AppOpsManager mAppOpsManager;
216
217 class OpsCallback : public BnAppOpsCallback {
218 public:
219 OpsCallback(wp<BasicClient> client);
220 virtual void opChanged(int32_t op, const String16& packageName);
221
222 private:
223 wp<BasicClient> mClient;
224
225 }; // class OpsCallback
226
227 sp<OpsCallback> mOpsCallback;
228 // Track whether startCameraOps was called successfully, to avoid
229 // finishing what we didn't start.
230 bool mOpsActive;
231
232 // IAppOpsCallback interface, indirected through opListener
233 virtual void opChanged(int32_t op, const String16& packageName);
234 }; // class BasicClient
Igor Murashkin634a5152013-02-20 17:15:11 -0800235
236 class Client : public BnCamera, public BasicClient
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700237 {
238 public:
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800239 typedef ICameraClient TCamCallbacks;
240
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700241 // ICamera interface (see ICamera for details)
242 virtual void disconnect();
243 virtual status_t connect(const sp<ICameraClient>& client) = 0;
244 virtual status_t lock() = 0;
245 virtual status_t unlock() = 0;
Eino-Ville Talvala1ce7c342013-08-21 13:57:21 -0700246 virtual status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)=0;
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700247 virtual void setPreviewCallbackFlag(int flag) = 0;
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700248 virtual status_t setPreviewCallbackTarget(
249 const sp<IGraphicBufferProducer>& callbackProducer) = 0;
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700250 virtual status_t startPreview() = 0;
251 virtual void stopPreview() = 0;
252 virtual bool previewEnabled() = 0;
253 virtual status_t storeMetaDataInBuffers(bool enabled) = 0;
254 virtual status_t startRecording() = 0;
255 virtual void stopRecording() = 0;
256 virtual bool recordingEnabled() = 0;
257 virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;
258 virtual status_t autoFocus() = 0;
259 virtual status_t cancelAutoFocus() = 0;
260 virtual status_t takePicture(int msgType) = 0;
261 virtual status_t setParameters(const String8& params) = 0;
262 virtual String8 getParameters() const = 0;
263 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
264
265 // Interface used by CameraService
266 Client(const sp<CameraService>& cameraService,
267 const sp<ICameraClient>& cameraClient,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800268 const String16& clientPackageName,
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700269 int cameraId,
270 int cameraFacing,
Igor Murashkinecf17e82012-10-02 16:05:11 -0700271 int clientPid,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800272 uid_t clientUid,
Igor Murashkinecf17e82012-10-02 16:05:11 -0700273 int servicePid);
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700274 ~Client();
275
276 // return our camera client
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800277 const sp<ICameraClient>& getRemoteCallback() {
278 return mRemoteCallback;
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700279 }
280
Igor Murashkine7ee7632013-06-11 18:10:18 -0700281 virtual sp<IBinder> asBinderWrapper() {
282 return asBinder();
283 }
284
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700285 protected:
286 static Mutex* getClientLockFromCookie(void* user);
287 // convert client from cookie. Client lock should be acquired before getting Client.
288 static Client* getClientFromCookie(void* user);
289
Jianing Weicb0652e2014-03-12 18:29:36 -0700290 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
291 const CaptureResultExtras& resultExtras);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800292
Igor Murashkin634a5152013-02-20 17:15:11 -0800293 // Initialized in constructor
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700294
Igor Murashkin634a5152013-02-20 17:15:11 -0800295 // - The app-side Binder interface to receive callbacks from us
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800296 sp<ICameraClient> mRemoteCallback;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800297
298 }; // class Client
Igor Murashkin634a5152013-02-20 17:15:11 -0800299
300 class ProClient : public BnProCameraUser, public BasicClient {
301 public:
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800302 typedef IProCameraCallbacks TCamCallbacks;
303
Igor Murashkin634a5152013-02-20 17:15:11 -0800304 ProClient(const sp<CameraService>& cameraService,
305 const sp<IProCameraCallbacks>& remoteCallback,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800306 const String16& clientPackageName,
Igor Murashkin634a5152013-02-20 17:15:11 -0800307 int cameraId,
308 int cameraFacing,
309 int clientPid,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800310 uid_t clientUid,
Igor Murashkin634a5152013-02-20 17:15:11 -0800311 int servicePid);
312
313 virtual ~ProClient();
314
315 const sp<IProCameraCallbacks>& getRemoteCallback() {
316 return mRemoteCallback;
317 }
318
Igor Murashkin634a5152013-02-20 17:15:11 -0800319 /***
320 IProCamera implementation
321 ***/
Igor Murashkine6800ce2013-03-04 17:25:57 -0800322 virtual status_t connect(const sp<IProCameraCallbacks>& callbacks)
323 = 0;
324 virtual status_t exclusiveTryLock() = 0;
325 virtual status_t exclusiveLock() = 0;
326 virtual status_t exclusiveUnlock() = 0;
Igor Murashkin634a5152013-02-20 17:15:11 -0800327
Igor Murashkine6800ce2013-03-04 17:25:57 -0800328 virtual bool hasExclusiveLock() = 0;
Igor Murashkin634a5152013-02-20 17:15:11 -0800329
330 // Note that the callee gets a copy of the metadata.
331 virtual int submitRequest(camera_metadata_t* metadata,
Igor Murashkine6800ce2013-03-04 17:25:57 -0800332 bool streaming = false) = 0;
333 virtual status_t cancelRequest(int requestId) = 0;
Igor Murashkin634a5152013-02-20 17:15:11 -0800334
Igor Murashkinbfc99152013-02-27 12:55:20 -0800335 // Callbacks from camera service
Igor Murashkine6800ce2013-03-04 17:25:57 -0800336 virtual void onExclusiveLockStolen() = 0;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800337
Igor Murashkin634a5152013-02-20 17:15:11 -0800338 protected:
Jianing Weicb0652e2014-03-12 18:29:36 -0700339 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
340 const CaptureResultExtras& resultExtras);
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700341
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800342 sp<IProCameraCallbacks> mRemoteCallback;
343 }; // class ProClient
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700344
Mathias Agopian65ab4712010-07-14 17:59:35 -0700345private:
Igor Murashkin634a5152013-02-20 17:15:11 -0800346
347 // Delay-load the Camera HAL module
348 virtual void onFirstRef();
349
Igor Murashkine6800ce2013-03-04 17:25:57 -0800350 // Step 1. Check if we can connect, before we acquire the service lock.
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700351 status_t validateConnect(int cameraId,
Igor Murashkine6800ce2013-03-04 17:25:57 -0800352 /*inout*/
353 int& clientUid) const;
354
355 // Step 2. Check if we can connect, after we acquire the service lock.
356 bool canConnectUnsafe(int cameraId,
357 const String16& clientPackageName,
358 const sp<IBinder>& remoteCallback,
359 /*out*/
Igor Murashkine7ee7632013-06-11 18:10:18 -0700360 sp<BasicClient> &client);
Igor Murashkine6800ce2013-03-04 17:25:57 -0800361
362 // When connection is successful, initialize client and track its death
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700363 status_t connectFinishUnsafe(const sp<BasicClient>& client,
Igor Murashkine7ee7632013-06-11 18:10:18 -0700364 const sp<IBinder>& remoteCallback);
Igor Murashkine6800ce2013-03-04 17:25:57 -0800365
Igor Murashkin634a5152013-02-20 17:15:11 -0800366 virtual sp<BasicClient> getClientByRemote(const wp<IBinder>& cameraClient);
367
Mathias Agopian65ab4712010-07-14 17:59:35 -0700368 Mutex mServiceLock;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700369 // either a Client or CameraDeviceClient
370 wp<BasicClient> mClient[MAX_CAMERAS]; // protected by mServiceLock
Keun young Parkd8973a72012-03-28 14:13:09 -0700371 Mutex mClientLock[MAX_CAMERAS]; // prevent Client destruction inside callbacks
Mathias Agopian65ab4712010-07-14 17:59:35 -0700372 int mNumberOfCameras;
373
Igor Murashkin634a5152013-02-20 17:15:11 -0800374 typedef wp<ProClient> weak_pro_client_ptr;
375 Vector<weak_pro_client_ptr> mProClientList[MAX_CAMERAS];
376
Igor Murashkinecf17e82012-10-02 16:05:11 -0700377 // needs to be called with mServiceLock held
Igor Murashkine7ee7632013-06-11 18:10:18 -0700378 sp<BasicClient> findClientUnsafe(const wp<IBinder>& cameraClient, int& outIndex);
Igor Murashkin634a5152013-02-20 17:15:11 -0800379 sp<ProClient> findProClientUnsafe(
380 const wp<IBinder>& cameraCallbacksRemote);
Igor Murashkinecf17e82012-10-02 16:05:11 -0700381
Mathias Agopian65ab4712010-07-14 17:59:35 -0700382 // atomics to record whether the hardware is allocated to some client.
383 volatile int32_t mBusy[MAX_CAMERAS];
384 void setCameraBusy(int cameraId);
385 void setCameraFree(int cameraId);
386
387 // sounds
Chih-Chung Changff4f55c2011-10-17 19:03:12 +0800388 MediaPlayer* newMediaPlayer(const char *file);
389
Mathias Agopian65ab4712010-07-14 17:59:35 -0700390 Mutex mSoundLock;
391 sp<MediaPlayer> mSoundPlayer[NUM_SOUNDS];
392 int mSoundRef; // reference count (release all MediaPlayer when 0)
393
Iliyan Malchev8951a972011-04-14 16:55:59 -0700394 camera_module_t *mModule;
Igor Murashkinecf17e82012-10-02 16:05:11 -0700395
Igor Murashkinbfc99152013-02-27 12:55:20 -0800396 Vector<sp<ICameraServiceListener> >
397 mListenerList;
398
399 // guard only mStatusList and the broadcasting of ICameraServiceListener
Igor Murashkincba2c162013-03-20 15:56:31 -0700400 mutable Mutex mStatusMutex;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800401 ICameraServiceListener::Status
402 mStatusList[MAX_CAMERAS];
403
Igor Murashkincba2c162013-03-20 15:56:31 -0700404 // Read the current status (locks mStatusMutex)
405 ICameraServiceListener::Status
406 getStatus(int cameraId) const;
407
Igor Murashkin93747b92013-05-01 15:42:20 -0700408 typedef Vector<ICameraServiceListener::Status> StatusVector;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800409 // Broadcast the new status if it changed (locks the service mutex)
410 void updateStatus(
411 ICameraServiceListener::Status status,
Igor Murashkin93747b92013-05-01 15:42:20 -0700412 int32_t cameraId,
413 const StatusVector *rejectSourceStates = NULL);
Igor Murashkinbfc99152013-02-27 12:55:20 -0800414
Igor Murashkinecf17e82012-10-02 16:05:11 -0700415 // IBinder::DeathRecipient implementation
Igor Murashkinbfc99152013-02-27 12:55:20 -0800416 virtual void binderDied(const wp<IBinder> &who);
Igor Murashkin634a5152013-02-20 17:15:11 -0800417
418 // Helpers
Igor Murashkinbfc99152013-02-27 12:55:20 -0800419
420 bool isValidCameraId(int cameraId);
Ruben Brunkd1176ef2014-02-21 10:51:38 -0800421
422 bool setUpVendorTags();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700423
424 /**
425 * A mapping of camera ids to CameraParameters returned by that camera device.
426 *
427 * This cache is used to generate CameraCharacteristic metadata when using
428 * the HAL1 shim.
429 */
430 KeyedVector<int, CameraParameters> mShimParams;
431
432 /**
433 * Initialize and cache the metadata used by the HAL1 shim for a given cameraId.
434 *
435 * Returns OK on success, or a negative error code.
436 */
437 status_t initializeShimMetadata(int cameraId);
438
439 /**
Igor Murashkin65d14b92014-06-17 12:03:20 -0700440 * Get the cached CameraParameters for the camera. If they haven't been
441 * cached yet, then initialize them for the first time.
442 *
443 * Returns OK on success, or a negative error code.
444 */
445 status_t getLegacyParametersLazy(int cameraId, /*out*/CameraParameters* parameters);
446
447 /**
Ruben Brunkb2119af2014-05-09 19:57:56 -0700448 * Generate the CameraCharacteristics metadata required by the Camera2 API
449 * from the available HAL1 CameraParameters and CameraInfo.
450 *
451 * Returns OK on success, or a negative error code.
452 */
453 status_t generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo);
454
455 /**
456 * Connect a new camera client. This should only be used while holding the
457 * mutex for mServiceLock.
458 *
459 * Returns OK on success, or a negative error code.
460 */
Igor Murashkina858ea02014-08-19 14:53:08 -0700461 status_t connectHelperLocked(
462 /*out*/
463 sp<Client>& client,
464 /*in*/
465 const sp<ICameraClient>& cameraClient,
466 int cameraId,
467 const String16& clientPackageName,
468 int clientUid,
469 int callingPid,
470 int halVersion = CAMERA_HAL_API_VERSION_UNSPECIFIED,
471 bool legacyMode = false);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700472};
473
474} // namespace android
475
476#endif