blob: c12793a8a9672a7e179780cfe19e6f2c14d8564b [file] [log] [blame]
Igor Murashkin44cfcf02013-03-01 16:22:28 -08001/*
2 * Copyright (C) 2013 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 */
16
17#ifndef ANDROID_SERVERS_CAMERA_CAMERA2CLIENT_BASE_H
18#define ANDROID_SERVERS_CAMERA_CAMERA2CLIENT_BASE_H
19
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070020#include "common/CameraDeviceBase.h"
Igor Murashkin44cfcf02013-03-01 16:22:28 -080021
22namespace android {
23
24class IMemory;
25
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070026class CameraService;
27
Igor Murashkin44cfcf02013-03-01 16:22:28 -080028template <typename TClientBase>
29class Camera2ClientBase :
30 public TClientBase,
31 public CameraDeviceBase::NotificationListener
32{
33public:
34 typedef typename TClientBase::TCamCallbacks TCamCallbacks;
35
36 /**
37 * Base binder interface (see ICamera/IProCameraUser for details)
38 */
39 virtual status_t connect(const sp<TCamCallbacks>& callbacks);
40 virtual void disconnect();
41
42 /**
43 * Interface used by CameraService
44 */
45
46 // TODO: too many params, move into a ClientArgs<T>
47 Camera2ClientBase(const sp<CameraService>& cameraService,
48 const sp<TCamCallbacks>& remoteCallback,
49 const String16& clientPackageName,
50 int cameraId,
51 int cameraFacing,
52 int clientPid,
53 uid_t clientUid,
54 int servicePid);
55 virtual ~Camera2ClientBase();
56
57 virtual status_t initialize(camera_module_t *module);
Eino-Ville Talvalac9ab2b02016-01-13 10:07:04 -080058 virtual status_t dumpClient(int fd, const Vector<String16>& args);
Igor Murashkin44cfcf02013-03-01 16:22:28 -080059
60 /**
61 * CameraDeviceBase::NotificationListener implementation
62 */
63
64 virtual void notifyError(int errorCode, int arg1, int arg2);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070065 virtual void notifyIdle();
66 virtual void notifyShutter(int requestId, nsecs_t timestamp);
Igor Murashkin44cfcf02013-03-01 16:22:28 -080067 virtual void notifyAutoFocus(uint8_t newState, int triggerId);
68 virtual void notifyAutoExposure(uint8_t newState, int triggerId);
69 virtual void notifyAutoWhitebalance(uint8_t newState,
70 int triggerId);
71
72
73 int getCameraId() const;
74 const sp<CameraDeviceBase>&
75 getCameraDevice();
76 const sp<CameraService>&
77 getCameraService();
78
79 /**
80 * Interface used by independent components of CameraClient2Base.
81 */
82
83 // Simple class to ensure that access to TCamCallbacks is serialized
84 // by requiring mRemoteCallbackLock to be locked before access to
85 // mRemoteCallback is possible.
86 class SharedCameraCallbacks {
87 public:
88 class Lock {
89 public:
90 Lock(SharedCameraCallbacks &client);
91 ~Lock();
92 sp<TCamCallbacks> &mRemoteCallback;
93 private:
94 SharedCameraCallbacks &mSharedClient;
95 };
96 SharedCameraCallbacks(const sp<TCamCallbacks>& client);
97 SharedCameraCallbacks& operator=(const sp<TCamCallbacks>& client);
98 void clear();
99 private:
100 sp<TCamCallbacks> mRemoteCallback;
101 mutable Mutex mRemoteCallbackLock;
102 } mSharedCameraCallbacks;
103
104protected:
105
Igor Murashkine7ee7632013-06-11 18:10:18 -0700106 virtual sp<IBinder> asBinderWrapper() {
107 return IInterface::asBinder();
108 }
109
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800110 virtual status_t dumpDevice(int fd, const Vector<String16>& args);
111
112 /** Binder client interface-related private members */
113
114 // Mutex that must be locked by methods implementing the binder client
115 // interface. Ensures serialization between incoming client calls.
116 // All methods in this class hierarchy that append 'L' to the name assume
117 // that mBinderSerializationLock is locked when they're called
118 mutable Mutex mBinderSerializationLock;
119
120 /** CameraDeviceBase instance wrapping HAL2+ entry */
121
122 sp<CameraDeviceBase> mDevice;
123
124 /** Utility members */
125
126 // Verify that caller is the owner of the camera
127 status_t checkPid(const char *checkLocation) const;
128
129 virtual void detachDevice();
130};
131
132}; // namespace android
133
134#endif