blob: 89b27f8fe1becb2db84ec14e4b2345f8443c565f [file] [log] [blame]
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001/*
2 * Copyright (C) 2019 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_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H
18#define ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H
19
20#include <android/hardware/camera2/BnCameraOfflineSession.h>
21#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
Emilian Peevd99c8ae2019-11-26 13:19:13 -080022#include "common/FrameProcessorBase.h"
23#include "common/CameraDeviceBase.h"
Yin-Chia Yehb978c382019-10-30 00:22:37 -070024#include "CameraService.h"
Emilian Peev4697b642019-11-19 17:11:14 -080025#include "CompositeStream.h"
Yin-Chia Yehb978c382019-10-30 00:22:37 -070026
27namespace android {
28
29using android::hardware::camera2::ICameraDeviceCallbacks;
Emilian Peev4697b642019-11-19 17:11:14 -080030using camera3::CompositeStream;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070031
Emilian Peevb2bc5a42019-11-20 16:02:14 -080032// Client for offline session. Note that offline session client does not affect camera service's
33// client arbitration logic. It is camera HAL's decision to decide whether a normal camera
34// client is conflicting with existing offline client(s).
35// The other distinctive difference between offline clients and normal clients is that normal
36// clients are created through ICameraService binder calls, while the offline session client
37// is created through ICameraDeviceUser::switchToOffline call.
Yin-Chia Yehb978c382019-10-30 00:22:37 -070038class CameraOfflineSessionClient :
Emilian Peevb2bc5a42019-11-20 16:02:14 -080039 public CameraService::BasicClient,
Emilian Peevd99c8ae2019-11-26 13:19:13 -080040 public hardware::camera2::BnCameraOfflineSession,
41 public camera2::FrameProcessorBase::FilteredListener,
42 public NotificationListener
Yin-Chia Yehb978c382019-10-30 00:22:37 -070043{
44public:
45 CameraOfflineSessionClient(
46 const sp<CameraService>& cameraService,
47 sp<CameraOfflineSessionBase> session,
Emilian Peev4697b642019-11-19 17:11:14 -080048 const KeyedVector<sp<IBinder>, sp<CompositeStream>>& offlineCompositeStreamMap,
Yin-Chia Yehb978c382019-10-30 00:22:37 -070049 const sp<ICameraDeviceCallbacks>& remoteCallback,
50 const String16& clientPackageName,
Jooyung Han3f9a3b42020-01-23 12:27:18 +090051 const std::optional<String16>& clientFeatureId,
Emilian Peev8b64f282021-03-25 16:49:57 -070052 const String8& cameraIdStr, int cameraFacing, int sensorOrientation,
Yin-Chia Yehb978c382019-10-30 00:22:37 -070053 int clientPid, uid_t clientUid, int servicePid) :
Emilian Peevb2bc5a42019-11-20 16:02:14 -080054 CameraService::BasicClient(
55 cameraService,
56 IInterface::asBinder(remoteCallback),
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080057 // (v)ndk doesn't have offline session support
58 clientPackageName, /*overridePackageName*/false, clientFeatureId,
Austin Borger18b30a72022-10-27 12:20:29 -070059 cameraIdStr, cameraFacing, sensorOrientation, clientPid, clientUid, servicePid,
60 /*overrideToPortrait*/false),
Emilian Peev4697b642019-11-19 17:11:14 -080061 mRemoteCallback(remoteCallback), mOfflineSession(session),
62 mCompositeStreamMap(offlineCompositeStreamMap) {}
Yin-Chia Yehb978c382019-10-30 00:22:37 -070063
Emilian Peevb2bc5a42019-11-20 16:02:14 -080064 virtual ~CameraOfflineSessionClient() {}
Yin-Chia Yehb978c382019-10-30 00:22:37 -070065
Emilian Peevd99c8ae2019-11-26 13:19:13 -080066 sp<IBinder> asBinderWrapper() override {
Emilian Peevb2bc5a42019-11-20 16:02:14 -080067 return IInterface::asBinder(this);
Yin-Chia Yehb978c382019-10-30 00:22:37 -070068 }
69
Emilian Peevd99c8ae2019-11-26 13:19:13 -080070 binder::Status disconnect() override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070071
Emilian Peevd99c8ae2019-11-26 13:19:13 -080072 status_t dump(int /*fd*/, const Vector<String16>& /*args*/) override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070073
Emilian Peevd99c8ae2019-11-26 13:19:13 -080074 status_t dumpClient(int /*fd*/, const Vector<String16>& /*args*/) override;
Emilian Peevb2bc5a42019-11-20 16:02:14 -080075
Avichal Rakesh7e53cad2021-10-05 13:46:30 -070076 status_t startWatchingTags(const String8 &tags, int outFd) override;
77 status_t stopWatchingTags(int outFd) override;
78 status_t dumpWatchedEventsToVector(std::vector<std::string> &out) override;
79
Emilian Peevd99c8ae2019-11-26 13:19:13 -080080 status_t initialize(sp<CameraProviderManager> /*manager*/,
Emilian Peevb2bc5a42019-11-20 16:02:14 -080081 const String8& /*monitorTags*/) override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070082
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -080083 status_t setRotateAndCropOverride(uint8_t rotateAndCrop) override;
84
Bharatt Kukreja7146ced2022-10-25 15:45:29 +000085 status_t setAutoframingOverride(uint8_t autoframingValue) override;
86
Eino-Ville Talvala305cec62020-11-12 14:18:17 -080087 bool supportsCameraMute() override;
88 status_t setCameraMute(bool enabled) override;
89
Ravneetaeb20dc2022-03-30 05:33:03 +000090 status_t setCameraServiceWatchdog(bool enabled) override;
91
Emilian Peevb2bc5a42019-11-20 16:02:14 -080092 // permissions management
Emilian Peevd99c8ae2019-11-26 13:19:13 -080093 status_t startCameraOps() override;
94 status_t finishCameraOps() override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070095
Emilian Peevd99c8ae2019-11-26 13:19:13 -080096 // FilteredResultListener API
97 void onResultAvailable(const CaptureResult& result) override;
98
99 // NotificationListener API
100 void notifyError(int32_t errorCode, const CaptureResultExtras& resultExtras) override;
101 void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp) override;
Austin Borger4a870a32022-02-25 01:48:41 +0000102 status_t notifyActive(float maxPreviewFps) override;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700103 void notifyIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError,
104 const std::vector<hardware::CameraStreamStats>& streamStats) override;
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800105 void notifyAutoFocus(uint8_t newState, int triggerId) override;
106 void notifyAutoExposure(uint8_t newState, int triggerId) override;
107 void notifyAutoWhitebalance(uint8_t newState, int triggerId) override;
108 void notifyPrepared(int streamId) override;
109 void notifyRequestQueueEmpty() override;
110 void notifyRepeatingRequestError(long lastFrameNumber) override;
Cliff Wud3a05312021-04-26 23:07:31 +0800111 status_t injectCamera(const String8& injectedCamId,
112 sp<CameraProviderManager> manager) override;
113 status_t stopInjection() override;
Emilian Peev4697b642019-11-19 17:11:14 -0800114
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700115private:
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800116 mutable Mutex mBinderSerializationLock;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700117
118 sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700119
120 sp<CameraOfflineSessionBase> mOfflineSession;
Emilian Peev4697b642019-11-19 17:11:14 -0800121
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800122 sp<camera2::FrameProcessorBase> mFrameProcessor;
123
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800124 // Offline composite stream map, output surface -> composite stream
Emilian Peev4697b642019-11-19 17:11:14 -0800125 KeyedVector<sp<IBinder>, sp<CompositeStream>> mCompositeStreamMap;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700126};
127
128} // namespace android
129
130#endif // ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H