blob: 9fd0a782edf0378a028933550a62e3ea2008e541 [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"
Yin-Chia Yehe074a932015-01-30 10:29:02 -080021#include "common/CameraModule.h"
Jianing Weicb0652e2014-03-12 18:29:36 -070022#include "camera/CaptureResult.h"
Igor Murashkin44cfcf02013-03-01 16:22:28 -080023
24namespace android {
25
26class IMemory;
27
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070028class CameraService;
29
Igor Murashkin44cfcf02013-03-01 16:22:28 -080030template <typename TClientBase>
31class Camera2ClientBase :
32 public TClientBase,
33 public CameraDeviceBase::NotificationListener
34{
35public:
36 typedef typename TClientBase::TCamCallbacks TCamCallbacks;
37
38 /**
Ruben Brunk9efdf952015-03-18 23:11:57 -070039 * Base binder interface (see ICamera/ICameraDeviceUser for details)
Igor Murashkin44cfcf02013-03-01 16:22:28 -080040 */
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080041 virtual status_t connect(const sp<TCamCallbacks>& callbacks);
42 virtual binder::Status disconnect();
Igor Murashkin44cfcf02013-03-01 16:22:28 -080043
44 /**
45 * Interface used by CameraService
46 */
47
48 // TODO: too many params, move into a ClientArgs<T>
49 Camera2ClientBase(const sp<CameraService>& cameraService,
50 const sp<TCamCallbacks>& remoteCallback,
51 const String16& clientPackageName,
52 int cameraId,
53 int cameraFacing,
54 int clientPid,
55 uid_t clientUid,
56 int servicePid);
57 virtual ~Camera2ClientBase();
58
Yin-Chia Yehe074a932015-01-30 10:29:02 -080059 virtual status_t initialize(CameraModule *module);
Eino-Ville Talvalac4003962016-01-13 10:07:04 -080060 virtual status_t dumpClient(int fd, const Vector<String16>& args);
Igor Murashkin44cfcf02013-03-01 16:22:28 -080061
62 /**
63 * CameraDeviceBase::NotificationListener implementation
64 */
65
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080066 virtual void notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -070067 const CaptureResultExtras& resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070068 virtual void notifyIdle();
Jianing Weicb0652e2014-03-12 18:29:36 -070069 virtual void notifyShutter(const CaptureResultExtras& resultExtras,
70 nsecs_t timestamp);
Igor Murashkin44cfcf02013-03-01 16:22:28 -080071 virtual void notifyAutoFocus(uint8_t newState, int triggerId);
72 virtual void notifyAutoExposure(uint8_t newState, int triggerId);
73 virtual void notifyAutoWhitebalance(uint8_t newState,
74 int triggerId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -070075 virtual void notifyPrepared(int streamId);
Shuzhen Wang9d066012016-09-30 11:30:20 -070076 virtual void notifyRequestQueueEmpty();
Chien-Yu Chene8c535e2016-04-14 12:18:26 -070077 virtual void notifyRepeatingRequestError(long lastFrameNumber);
Igor Murashkin44cfcf02013-03-01 16:22:28 -080078
79 int getCameraId() const;
80 const sp<CameraDeviceBase>&
81 getCameraDevice();
Yin-Chia Yehcd8fce82014-06-18 10:51:34 -070082 int getCameraDeviceVersion() const;
Igor Murashkin44cfcf02013-03-01 16:22:28 -080083 const sp<CameraService>&
84 getCameraService();
85
86 /**
87 * Interface used by independent components of CameraClient2Base.
88 */
89
90 // Simple class to ensure that access to TCamCallbacks is serialized
91 // by requiring mRemoteCallbackLock to be locked before access to
92 // mRemoteCallback is possible.
93 class SharedCameraCallbacks {
94 public:
95 class Lock {
96 public:
Chih-Hung Hsieh8b0b9712016-08-09 14:25:53 -070097 explicit Lock(SharedCameraCallbacks &client);
Igor Murashkin44cfcf02013-03-01 16:22:28 -080098 ~Lock();
99 sp<TCamCallbacks> &mRemoteCallback;
100 private:
101 SharedCameraCallbacks &mSharedClient;
102 };
Chih-Hung Hsieh8b0b9712016-08-09 14:25:53 -0700103 explicit SharedCameraCallbacks(const sp<TCamCallbacks>& client);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800104 SharedCameraCallbacks& operator=(const sp<TCamCallbacks>& client);
105 void clear();
106 private:
107 sp<TCamCallbacks> mRemoteCallback;
108 mutable Mutex mRemoteCallbackLock;
109 } mSharedCameraCallbacks;
110
111protected:
112
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -0700113 // The PID provided in the constructor call
114 pid_t mInitialClientPid;
115
Igor Murashkine7ee7632013-06-11 18:10:18 -0700116 virtual sp<IBinder> asBinderWrapper() {
Marco Nelissen06b46062014-11-14 07:58:25 -0800117 return IInterface::asBinder(this);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700118 }
119
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800120 virtual status_t dumpDevice(int fd, const Vector<String16>& args);
121
122 /** Binder client interface-related private members */
123
124 // Mutex that must be locked by methods implementing the binder client
125 // interface. Ensures serialization between incoming client calls.
126 // All methods in this class hierarchy that append 'L' to the name assume
127 // that mBinderSerializationLock is locked when they're called
128 mutable Mutex mBinderSerializationLock;
129
Eino-Ville Talvalad309fb92015-11-25 12:12:45 -0800130 /** CameraDeviceBase instance wrapping HAL3+ entry */
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800131
Yin-Chia Yehcd8fce82014-06-18 10:51:34 -0700132 const int mDeviceVersion;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800133 sp<CameraDeviceBase> mDevice;
134
135 /** Utility members */
136
137 // Verify that caller is the owner of the camera
138 status_t checkPid(const char *checkLocation) const;
139
140 virtual void detachDevice();
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700141
142 bool mDeviceActive;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800143};
144
145}; // namespace android
146
147#endif