blob: 6246f7baea06e791278697a387535c764d3af99d [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"
Jianing Weicb0652e2014-03-12 18:29:36 -070021#include "camera/CaptureResult.h"
Igor Murashkin44cfcf02013-03-01 16:22:28 -080022
23namespace android {
24
25class IMemory;
26
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070027class CameraService;
28
Igor Murashkin44cfcf02013-03-01 16:22:28 -080029template <typename TClientBase>
30class Camera2ClientBase :
31 public TClientBase,
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080032 public NotificationListener
Igor Murashkin44cfcf02013-03-01 16:22:28 -080033{
34public:
35 typedef typename TClientBase::TCamCallbacks TCamCallbacks;
36
37 /**
Ruben Brunk9efdf952015-03-18 23:11:57 -070038 * Base binder interface (see ICamera/ICameraDeviceUser for details)
Igor Murashkin44cfcf02013-03-01 16:22:28 -080039 */
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080040 virtual status_t connect(const sp<TCamCallbacks>& callbacks);
41 virtual binder::Status disconnect();
Igor Murashkin44cfcf02013-03-01 16:22:28 -080042
43 /**
44 * Interface used by CameraService
45 */
46
47 // TODO: too many params, move into a ClientArgs<T>
48 Camera2ClientBase(const sp<CameraService>& cameraService,
49 const sp<TCamCallbacks>& remoteCallback,
50 const String16& clientPackageName,
Jooyung Han3f9a3b42020-01-23 12:27:18 +090051 const std::optional<String16>& clientFeatureId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080052 const String8& cameraId,
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080053 int api1CameraId,
Igor Murashkin44cfcf02013-03-01 16:22:28 -080054 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070055 int sensorOrientation,
Igor Murashkin44cfcf02013-03-01 16:22:28 -080056 int clientPid,
57 uid_t clientUid,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -070058 int servicePid,
59 bool overrideForPerfClass);
Igor Murashkin44cfcf02013-03-01 16:22:28 -080060 virtual ~Camera2ClientBase();
61
Emilian Peevbd8c5032018-02-14 23:05:40 +000062 virtual status_t initialize(sp<CameraProviderManager> manager, const String8& monitorTags);
Eino-Ville Talvalac4003962016-01-13 10:07:04 -080063 virtual status_t dumpClient(int fd, const Vector<String16>& args);
Igor Murashkin44cfcf02013-03-01 16:22:28 -080064
65 /**
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080066 * NotificationListener implementation
Igor Murashkin44cfcf02013-03-01 16:22:28 -080067 */
68
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080069 virtual void notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -070070 const CaptureResultExtras& resultExtras);
Eino-Ville Talvala178e8232021-04-16 18:41:39 -070071 virtual status_t notifyActive(); // Returns errors on app ops permission failures
Shuzhen Wang316781a2020-08-18 18:11:01 -070072 virtual void notifyIdle(int64_t requestCount, int64_t resultErrorCount,
73 bool deviceError,
74 const std::vector<hardware::CameraStreamStats>& streamStats);
Jianing Weicb0652e2014-03-12 18:29:36 -070075 virtual void notifyShutter(const CaptureResultExtras& resultExtras,
76 nsecs_t timestamp);
Igor Murashkin44cfcf02013-03-01 16:22:28 -080077 virtual void notifyAutoFocus(uint8_t newState, int triggerId);
78 virtual void notifyAutoExposure(uint8_t newState, int triggerId);
79 virtual void notifyAutoWhitebalance(uint8_t newState,
80 int triggerId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -070081 virtual void notifyPrepared(int streamId);
Shuzhen Wang9d066012016-09-30 11:30:20 -070082 virtual void notifyRequestQueueEmpty();
Chien-Yu Chene8c535e2016-04-14 12:18:26 -070083 virtual void notifyRepeatingRequestError(long lastFrameNumber);
Igor Murashkin44cfcf02013-03-01 16:22:28 -080084
85 int getCameraId() const;
86 const sp<CameraDeviceBase>&
87 getCameraDevice();
Yin-Chia Yehcd8fce82014-06-18 10:51:34 -070088 int getCameraDeviceVersion() const;
Igor Murashkin44cfcf02013-03-01 16:22:28 -080089 const sp<CameraService>&
90 getCameraService();
91
92 /**
93 * Interface used by independent components of CameraClient2Base.
94 */
95
96 // Simple class to ensure that access to TCamCallbacks is serialized
97 // by requiring mRemoteCallbackLock to be locked before access to
98 // mRemoteCallback is possible.
99 class SharedCameraCallbacks {
100 public:
101 class Lock {
102 public:
Chih-Hung Hsieh8b0b9712016-08-09 14:25:53 -0700103 explicit Lock(SharedCameraCallbacks &client);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800104 ~Lock();
105 sp<TCamCallbacks> &mRemoteCallback;
106 private:
107 SharedCameraCallbacks &mSharedClient;
108 };
Chih-Hung Hsieh8b0b9712016-08-09 14:25:53 -0700109 explicit SharedCameraCallbacks(const sp<TCamCallbacks>& client);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800110 SharedCameraCallbacks& operator=(const sp<TCamCallbacks>& client);
111 void clear();
112 private:
113 sp<TCamCallbacks> mRemoteCallback;
114 mutable Mutex mRemoteCallbackLock;
115 } mSharedCameraCallbacks;
116
117protected:
118
Eino-Ville Talvalab9d2f332014-09-18 17:24:22 -0700119 // The PID provided in the constructor call
120 pid_t mInitialClientPid;
121
Igor Murashkine7ee7632013-06-11 18:10:18 -0700122 virtual sp<IBinder> asBinderWrapper() {
Marco Nelissen06b46062014-11-14 07:58:25 -0800123 return IInterface::asBinder(this);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700124 }
125
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800126 virtual status_t dumpDevice(int fd, const Vector<String16>& args);
127
128 /** Binder client interface-related private members */
129
130 // Mutex that must be locked by methods implementing the binder client
131 // interface. Ensures serialization between incoming client calls.
132 // All methods in this class hierarchy that append 'L' to the name assume
133 // that mBinderSerializationLock is locked when they're called
134 mutable Mutex mBinderSerializationLock;
135
Eino-Ville Talvalad309fb92015-11-25 12:12:45 -0800136 /** CameraDeviceBase instance wrapping HAL3+ entry */
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800137
Yin-Chia Yehcd8fce82014-06-18 10:51:34 -0700138 const int mDeviceVersion;
Yin-Chia Yehc5248132018-08-15 12:19:20 -0700139
140 // Set to const to avoid mDevice being updated (update of sp<> is racy) during
141 // dumpDevice (which is important to be lock free for debugging purpose)
142 const sp<CameraDeviceBase> mDevice;
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800143
144 /** Utility members */
145
146 // Verify that caller is the owner of the camera
147 status_t checkPid(const char *checkLocation) const;
148
149 virtual void detachDevice();
Eino-Ville Talvala412fe562015-08-20 17:08:32 -0700150
151 bool mDeviceActive;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800152
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800153 const int mApi1CameraId; // -1 if client is API2
154
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800155private:
156 template<typename TProviderPtr>
Emilian Peevbd8c5032018-02-14 23:05:40 +0000157 status_t initializeImpl(TProviderPtr providerPtr, const String8& monitorTags);
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800158};
159
160}; // namespace android
161
162#endif