blob: 7d0df3a1d7144f94bc9035e7f2050757f6d7367c [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
Yin-Chia Yehe074a932015-01-30 10:29:02 -080040#include "common/CameraModule.h"
41
Mathias Agopian65ab4712010-07-14 17:59:35 -070042/* This needs to be increased if we can have more cameras */
43#define MAX_CAMERAS 2
44
45namespace android {
46
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -070047extern volatile int32_t gLogLevel;
48
Mathias Agopian65ab4712010-07-14 17:59:35 -070049class MemoryHeapBase;
50class MediaPlayer;
51
Mathias Agopian5462fc92010-07-14 18:41:18 -070052class CameraService :
53 public BinderService<CameraService>,
Igor Murashkinecf17e82012-10-02 16:05:11 -070054 public BnCameraService,
Igor Murashkincba2c162013-03-20 15:56:31 -070055 public IBinder::DeathRecipient,
56 public camera_module_callbacks_t
Mathias Agopian65ab4712010-07-14 17:59:35 -070057{
Mathias Agopian5462fc92010-07-14 18:41:18 -070058 friend class BinderService<CameraService>;
Mathias Agopian65ab4712010-07-14 17:59:35 -070059public:
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -070060 class Client;
Igor Murashkin634a5152013-02-20 17:15:11 -080061 class BasicClient;
62
63 // Implementation of BinderService<T>
Mathias Agopian5462fc92010-07-14 18:41:18 -070064 static char const* getServiceName() { return "media.camera"; }
Mathias Agopian65ab4712010-07-14 17:59:35 -070065
66 CameraService();
67 virtual ~CameraService();
68
Igor Murashkin634a5152013-02-20 17:15:11 -080069 /////////////////////////////////////////////////////////////////////
Igor Murashkincba2c162013-03-20 15:56:31 -070070 // HAL Callbacks
71 virtual void onDeviceStatusChanged(int cameraId,
72 int newStatus);
73
74 /////////////////////////////////////////////////////////////////////
Igor Murashkin634a5152013-02-20 17:15:11 -080075 // ICameraService
Mathias Agopian65ab4712010-07-14 17:59:35 -070076 virtual int32_t getNumberOfCameras();
77 virtual status_t getCameraInfo(int cameraId,
78 struct CameraInfo* cameraInfo);
Zhijun He2b59be82013-09-25 10:14:30 -070079 virtual status_t getCameraCharacteristics(int cameraId,
80 CameraMetadata* cameraInfo);
Ruben Brunkd1176ef2014-02-21 10:51:38 -080081 virtual status_t getCameraVendorTagDescriptor(/*out*/ sp<VendorTagDescriptor>& desc);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080082
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070083 virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId,
84 const String16& clientPackageName, int clientUid,
85 /*out*/
86 sp<ICamera>& device);
87
Zhijun Heb10cdad2014-06-16 16:38:35 -070088 virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId,
89 int halVersion, const String16& clientPackageName, int clientUid,
90 /*out*/
91 sp<ICamera>& device);
92
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070093 virtual status_t connectPro(const sp<IProCameraCallbacks>& cameraCb,
94 int cameraId, const String16& clientPackageName, int clientUid,
95 /*out*/
96 sp<IProCameraUser>& device);
97
98 virtual status_t connectDevice(
Igor Murashkine7ee7632013-06-11 18:10:18 -070099 const sp<ICameraDeviceCallbacks>& cameraCb,
100 int cameraId,
101 const String16& clientPackageName,
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700102 int clientUid,
103 /*out*/
104 sp<ICameraDeviceUser>& device);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700105
Igor Murashkinbfc99152013-02-27 12:55:20 -0800106 virtual status_t addListener(const sp<ICameraServiceListener>& listener);
107 virtual status_t removeListener(
108 const sp<ICameraServiceListener>& listener);
109
Igor Murashkin65d14b92014-06-17 12:03:20 -0700110 virtual status_t getLegacyParameters(
111 int cameraId,
112 /*out*/
113 String16* parameters);
114
115 // OK = supports api of that version, -EOPNOTSUPP = does not support
116 virtual status_t supportsCameraApi(
117 int cameraId, int apiVersion);
118
Igor Murashkin634a5152013-02-20 17:15:11 -0800119 // Extra permissions checks
Mathias Agopian65ab4712010-07-14 17:59:35 -0700120 virtual status_t onTransact(uint32_t code, const Parcel& data,
121 Parcel* reply, uint32_t flags);
Igor Murashkin634a5152013-02-20 17:15:11 -0800122
123 virtual status_t dump(int fd, const Vector<String16>& args);
124
125 /////////////////////////////////////////////////////////////////////
126 // Client functionality
127 virtual void removeClientByRemote(const wp<IBinder>& remoteBinder);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700128
129 enum sound_kind {
130 SOUND_SHUTTER = 0,
131 SOUND_RECORDING = 1,
132 NUM_SOUNDS
133 };
134
135 void loadSound();
136 void playSound(sound_kind kind);
137 void releaseSound();
138
Igor Murashkin98e24722013-06-19 19:51:04 -0700139 /////////////////////////////////////////////////////////////////////
140 // CameraDeviceFactory functionality
141 int getDeviceVersion(int cameraId, int* facing = NULL);
142
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700143 /////////////////////////////////////////////////////////////////////
144 // Shared utilities
145 static status_t filterOpenErrorCode(status_t err);
146 static status_t filterGetInfoErrorCode(status_t err);
Igor Murashkin634a5152013-02-20 17:15:11 -0800147
148 /////////////////////////////////////////////////////////////////////
149 // CameraClient functionality
150
151 // returns plain pointer of client. Note that mClientLock should be acquired to
152 // prevent the client from destruction. The result can be NULL.
Igor Murashkine7ee7632013-06-11 18:10:18 -0700153 virtual BasicClient* getClientByIdUnsafe(int cameraId);
Igor Murashkin634a5152013-02-20 17:15:11 -0800154 virtual Mutex* getClientLockById(int cameraId);
155
156 class BasicClient : public virtual RefBase {
157 public:
Yin-Chia Yehe074a932015-01-30 10:29:02 -0800158 virtual status_t initialize(CameraModule *module) = 0;
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700159 virtual void disconnect();
Igor Murashkin634a5152013-02-20 17:15:11 -0800160
Igor Murashkine7ee7632013-06-11 18:10:18 -0700161 // because we can't virtually inherit IInterface, which breaks
162 // virtual inheritance
163 virtual sp<IBinder> asBinderWrapper() = 0;
164
Igor Murashkine6800ce2013-03-04 17:25:57 -0800165 // Return the remote callback binder object (e.g. IProCameraCallbacks)
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700166 sp<IBinder> getRemote() {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800167 return mRemoteBinder;
Igor Murashkin634a5152013-02-20 17:15:11 -0800168 }
169
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700170 virtual status_t dump(int fd, const Vector<String16>& args) = 0;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700171
Igor Murashkin634a5152013-02-20 17:15:11 -0800172 protected:
173 BasicClient(const sp<CameraService>& cameraService,
174 const sp<IBinder>& remoteCallback,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800175 const String16& clientPackageName,
Igor Murashkin634a5152013-02-20 17:15:11 -0800176 int cameraId,
177 int cameraFacing,
178 int clientPid,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800179 uid_t clientUid,
Igor Murashkin634a5152013-02-20 17:15:11 -0800180 int servicePid);
181
182 virtual ~BasicClient();
183
184 // the instance is in the middle of destruction. When this is set,
185 // the instance should not be accessed from callback.
186 // CameraService's mClientLock should be acquired to access this.
187 // - subclasses should set this to true in their destructors.
188 bool mDestructionStarted;
189
190 // these are initialized in the constructor.
191 sp<CameraService> mCameraService; // immutable after constructor
192 int mCameraId; // immutable after constructor
193 int mCameraFacing; // immutable after constructor
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800194 const String16 mClientPackageName;
Igor Murashkin634a5152013-02-20 17:15:11 -0800195 pid_t mClientPid;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800196 uid_t mClientUid; // immutable after constructor
Igor Murashkin634a5152013-02-20 17:15:11 -0800197 pid_t mServicePid; // immutable after constructor
198
199 // - The app-side Binder interface to receive callbacks from us
Igor Murashkine7ee7632013-06-11 18:10:18 -0700200 sp<IBinder> mRemoteBinder; // immutable after constructor
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800201
202 // permissions management
203 status_t startCameraOps();
204 status_t finishCameraOps();
205
206 // Notify client about a fatal error
Jianing Weicb0652e2014-03-12 18:29:36 -0700207 virtual void notifyError(
208 ICameraDeviceCallbacks::CameraErrorCode errorCode,
209 const CaptureResultExtras& resultExtras) = 0;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800210 private:
211 AppOpsManager mAppOpsManager;
212
213 class OpsCallback : public BnAppOpsCallback {
214 public:
215 OpsCallback(wp<BasicClient> client);
216 virtual void opChanged(int32_t op, const String16& packageName);
217
218 private:
219 wp<BasicClient> mClient;
220
221 }; // class OpsCallback
222
223 sp<OpsCallback> mOpsCallback;
224 // Track whether startCameraOps was called successfully, to avoid
225 // finishing what we didn't start.
226 bool mOpsActive;
227
228 // IAppOpsCallback interface, indirected through opListener
229 virtual void opChanged(int32_t op, const String16& packageName);
230 }; // class BasicClient
Igor Murashkin634a5152013-02-20 17:15:11 -0800231
232 class Client : public BnCamera, public BasicClient
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700233 {
234 public:
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800235 typedef ICameraClient TCamCallbacks;
236
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700237 // ICamera interface (see ICamera for details)
238 virtual void disconnect();
239 virtual status_t connect(const sp<ICameraClient>& client) = 0;
240 virtual status_t lock() = 0;
241 virtual status_t unlock() = 0;
Eino-Ville Talvala1ce7c342013-08-21 13:57:21 -0700242 virtual status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)=0;
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700243 virtual void setPreviewCallbackFlag(int flag) = 0;
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700244 virtual status_t setPreviewCallbackTarget(
245 const sp<IGraphicBufferProducer>& callbackProducer) = 0;
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700246 virtual status_t startPreview() = 0;
247 virtual void stopPreview() = 0;
248 virtual bool previewEnabled() = 0;
249 virtual status_t storeMetaDataInBuffers(bool enabled) = 0;
250 virtual status_t startRecording() = 0;
251 virtual void stopRecording() = 0;
252 virtual bool recordingEnabled() = 0;
253 virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;
254 virtual status_t autoFocus() = 0;
255 virtual status_t cancelAutoFocus() = 0;
256 virtual status_t takePicture(int msgType) = 0;
257 virtual status_t setParameters(const String8& params) = 0;
258 virtual String8 getParameters() const = 0;
259 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
260
261 // Interface used by CameraService
262 Client(const sp<CameraService>& cameraService,
263 const sp<ICameraClient>& cameraClient,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800264 const String16& clientPackageName,
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700265 int cameraId,
266 int cameraFacing,
Igor Murashkinecf17e82012-10-02 16:05:11 -0700267 int clientPid,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800268 uid_t clientUid,
Igor Murashkinecf17e82012-10-02 16:05:11 -0700269 int servicePid);
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700270 ~Client();
271
272 // return our camera client
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800273 const sp<ICameraClient>& getRemoteCallback() {
274 return mRemoteCallback;
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700275 }
276
Igor Murashkine7ee7632013-06-11 18:10:18 -0700277 virtual sp<IBinder> asBinderWrapper() {
Marco Nelissen06b46062014-11-14 07:58:25 -0800278 return asBinder(this);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700279 }
280
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700281 protected:
282 static Mutex* getClientLockFromCookie(void* user);
283 // convert client from cookie. Client lock should be acquired before getting Client.
284 static Client* getClientFromCookie(void* user);
285
Jianing Weicb0652e2014-03-12 18:29:36 -0700286 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
287 const CaptureResultExtras& resultExtras);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800288
Igor Murashkin634a5152013-02-20 17:15:11 -0800289 // Initialized in constructor
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700290
Igor Murashkin634a5152013-02-20 17:15:11 -0800291 // - The app-side Binder interface to receive callbacks from us
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800292 sp<ICameraClient> mRemoteCallback;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800293
294 }; // class Client
Igor Murashkin634a5152013-02-20 17:15:11 -0800295
296 class ProClient : public BnProCameraUser, public BasicClient {
297 public:
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800298 typedef IProCameraCallbacks TCamCallbacks;
299
Igor Murashkin634a5152013-02-20 17:15:11 -0800300 ProClient(const sp<CameraService>& cameraService,
301 const sp<IProCameraCallbacks>& remoteCallback,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800302 const String16& clientPackageName,
Igor Murashkin634a5152013-02-20 17:15:11 -0800303 int cameraId,
304 int cameraFacing,
305 int clientPid,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800306 uid_t clientUid,
Igor Murashkin634a5152013-02-20 17:15:11 -0800307 int servicePid);
308
309 virtual ~ProClient();
310
311 const sp<IProCameraCallbacks>& getRemoteCallback() {
312 return mRemoteCallback;
313 }
314
Igor Murashkin634a5152013-02-20 17:15:11 -0800315 /***
316 IProCamera implementation
317 ***/
Igor Murashkine6800ce2013-03-04 17:25:57 -0800318 virtual status_t connect(const sp<IProCameraCallbacks>& callbacks)
319 = 0;
320 virtual status_t exclusiveTryLock() = 0;
321 virtual status_t exclusiveLock() = 0;
322 virtual status_t exclusiveUnlock() = 0;
Igor Murashkin634a5152013-02-20 17:15:11 -0800323
Igor Murashkine6800ce2013-03-04 17:25:57 -0800324 virtual bool hasExclusiveLock() = 0;
Igor Murashkin634a5152013-02-20 17:15:11 -0800325
326 // Note that the callee gets a copy of the metadata.
327 virtual int submitRequest(camera_metadata_t* metadata,
Igor Murashkine6800ce2013-03-04 17:25:57 -0800328 bool streaming = false) = 0;
329 virtual status_t cancelRequest(int requestId) = 0;
Igor Murashkin634a5152013-02-20 17:15:11 -0800330
Igor Murashkinbfc99152013-02-27 12:55:20 -0800331 // Callbacks from camera service
Igor Murashkine6800ce2013-03-04 17:25:57 -0800332 virtual void onExclusiveLockStolen() = 0;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800333
Igor Murashkin634a5152013-02-20 17:15:11 -0800334 protected:
Jianing Weicb0652e2014-03-12 18:29:36 -0700335 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
336 const CaptureResultExtras& resultExtras);
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700337
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800338 sp<IProCameraCallbacks> mRemoteCallback;
339 }; // class ProClient
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700340
Mathias Agopian65ab4712010-07-14 17:59:35 -0700341private:
Igor Murashkin634a5152013-02-20 17:15:11 -0800342
343 // Delay-load the Camera HAL module
344 virtual void onFirstRef();
345
Igor Murashkine6800ce2013-03-04 17:25:57 -0800346 // Step 1. Check if we can connect, before we acquire the service lock.
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700347 status_t validateConnect(int cameraId,
Igor Murashkine6800ce2013-03-04 17:25:57 -0800348 /*inout*/
349 int& clientUid) const;
350
351 // Step 2. Check if we can connect, after we acquire the service lock.
352 bool canConnectUnsafe(int cameraId,
353 const String16& clientPackageName,
354 const sp<IBinder>& remoteCallback,
355 /*out*/
Igor Murashkine7ee7632013-06-11 18:10:18 -0700356 sp<BasicClient> &client);
Igor Murashkine6800ce2013-03-04 17:25:57 -0800357
358 // When connection is successful, initialize client and track its death
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700359 status_t connectFinishUnsafe(const sp<BasicClient>& client,
Igor Murashkine7ee7632013-06-11 18:10:18 -0700360 const sp<IBinder>& remoteCallback);
Igor Murashkine6800ce2013-03-04 17:25:57 -0800361
Igor Murashkin634a5152013-02-20 17:15:11 -0800362 virtual sp<BasicClient> getClientByRemote(const wp<IBinder>& cameraClient);
363
Mathias Agopian65ab4712010-07-14 17:59:35 -0700364 Mutex mServiceLock;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700365 // either a Client or CameraDeviceClient
366 wp<BasicClient> mClient[MAX_CAMERAS]; // protected by mServiceLock
Keun young Parkd8973a72012-03-28 14:13:09 -0700367 Mutex mClientLock[MAX_CAMERAS]; // prevent Client destruction inside callbacks
Mathias Agopian65ab4712010-07-14 17:59:35 -0700368 int mNumberOfCameras;
369
Igor Murashkin634a5152013-02-20 17:15:11 -0800370 typedef wp<ProClient> weak_pro_client_ptr;
371 Vector<weak_pro_client_ptr> mProClientList[MAX_CAMERAS];
372
Igor Murashkinecf17e82012-10-02 16:05:11 -0700373 // needs to be called with mServiceLock held
Igor Murashkine7ee7632013-06-11 18:10:18 -0700374 sp<BasicClient> findClientUnsafe(const wp<IBinder>& cameraClient, int& outIndex);
Igor Murashkin634a5152013-02-20 17:15:11 -0800375 sp<ProClient> findProClientUnsafe(
376 const wp<IBinder>& cameraCallbacksRemote);
Igor Murashkinecf17e82012-10-02 16:05:11 -0700377
Mathias Agopian65ab4712010-07-14 17:59:35 -0700378 // atomics to record whether the hardware is allocated to some client.
379 volatile int32_t mBusy[MAX_CAMERAS];
380 void setCameraBusy(int cameraId);
381 void setCameraFree(int cameraId);
382
383 // sounds
Chih-Chung Changff4f55c2011-10-17 19:03:12 +0800384 MediaPlayer* newMediaPlayer(const char *file);
385
Mathias Agopian65ab4712010-07-14 17:59:35 -0700386 Mutex mSoundLock;
387 sp<MediaPlayer> mSoundPlayer[NUM_SOUNDS];
388 int mSoundRef; // reference count (release all MediaPlayer when 0)
389
Yin-Chia Yehe074a932015-01-30 10:29:02 -0800390 CameraModule* mModule;
Igor Murashkinecf17e82012-10-02 16:05:11 -0700391
Igor Murashkinbfc99152013-02-27 12:55:20 -0800392 Vector<sp<ICameraServiceListener> >
393 mListenerList;
394
395 // guard only mStatusList and the broadcasting of ICameraServiceListener
Igor Murashkincba2c162013-03-20 15:56:31 -0700396 mutable Mutex mStatusMutex;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800397 ICameraServiceListener::Status
398 mStatusList[MAX_CAMERAS];
399
Igor Murashkincba2c162013-03-20 15:56:31 -0700400 // Read the current status (locks mStatusMutex)
401 ICameraServiceListener::Status
402 getStatus(int cameraId) const;
403
Igor Murashkin93747b92013-05-01 15:42:20 -0700404 typedef Vector<ICameraServiceListener::Status> StatusVector;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800405 // Broadcast the new status if it changed (locks the service mutex)
406 void updateStatus(
407 ICameraServiceListener::Status status,
Igor Murashkin93747b92013-05-01 15:42:20 -0700408 int32_t cameraId,
409 const StatusVector *rejectSourceStates = NULL);
Igor Murashkinbfc99152013-02-27 12:55:20 -0800410
Igor Murashkinecf17e82012-10-02 16:05:11 -0700411 // IBinder::DeathRecipient implementation
Igor Murashkinbfc99152013-02-27 12:55:20 -0800412 virtual void binderDied(const wp<IBinder> &who);
Igor Murashkin634a5152013-02-20 17:15:11 -0800413
414 // Helpers
Igor Murashkinbfc99152013-02-27 12:55:20 -0800415
416 bool isValidCameraId(int cameraId);
Ruben Brunkd1176ef2014-02-21 10:51:38 -0800417
418 bool setUpVendorTags();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700419
420 /**
421 * A mapping of camera ids to CameraParameters returned by that camera device.
422 *
423 * This cache is used to generate CameraCharacteristic metadata when using
424 * the HAL1 shim.
425 */
426 KeyedVector<int, CameraParameters> mShimParams;
427
428 /**
429 * Initialize and cache the metadata used by the HAL1 shim for a given cameraId.
430 *
431 * Returns OK on success, or a negative error code.
432 */
433 status_t initializeShimMetadata(int cameraId);
434
435 /**
Igor Murashkin65d14b92014-06-17 12:03:20 -0700436 * Get the cached CameraParameters for the camera. If they haven't been
437 * cached yet, then initialize them for the first time.
438 *
439 * Returns OK on success, or a negative error code.
440 */
441 status_t getLegacyParametersLazy(int cameraId, /*out*/CameraParameters* parameters);
442
443 /**
Ruben Brunkb2119af2014-05-09 19:57:56 -0700444 * Generate the CameraCharacteristics metadata required by the Camera2 API
445 * from the available HAL1 CameraParameters and CameraInfo.
446 *
447 * Returns OK on success, or a negative error code.
448 */
449 status_t generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo);
450
451 /**
452 * Connect a new camera client. This should only be used while holding the
453 * mutex for mServiceLock.
454 *
455 * Returns OK on success, or a negative error code.
456 */
Igor Murashkina858ea02014-08-19 14:53:08 -0700457 status_t connectHelperLocked(
458 /*out*/
459 sp<Client>& client,
460 /*in*/
461 const sp<ICameraClient>& cameraClient,
462 int cameraId,
463 const String16& clientPackageName,
464 int clientUid,
465 int callingPid,
466 int halVersion = CAMERA_HAL_API_VERSION_UNSPECIFIED,
467 bool legacyMode = false);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700468};
469
470} // namespace android
471
472#endif