blob: c6f3e0665fb64abd66329b367345387c1fa3db3f [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,
Austin Borger249e6592024-03-10 22:28:11 -070050 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,
Austin Borgered99f642023-06-01 16:51:35 -070051 const std::string& clientPackageName,
52 const std::optional<std::string>& clientFeatureId,
53 const std::string& cameraIdStr, int cameraFacing, int sensorOrientation,
Yin-Chia Yehb978c382019-10-30 00:22:37 -070054 int clientPid, uid_t clientUid, int servicePid) :
Emilian Peevb2bc5a42019-11-20 16:02:14 -080055 CameraService::BasicClient(
56 cameraService,
57 IInterface::asBinder(remoteCallback),
Austin Borger249e6592024-03-10 22:28:11 -070058 attributionAndPermissionUtils,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080059 // (v)ndk doesn't have offline session support
60 clientPackageName, /*overridePackageName*/false, clientFeatureId,
Austin Borger18b30a72022-10-27 12:20:29 -070061 cameraIdStr, cameraFacing, sensorOrientation, clientPid, clientUid, servicePid,
62 /*overrideToPortrait*/false),
Emilian Peev4697b642019-11-19 17:11:14 -080063 mRemoteCallback(remoteCallback), mOfflineSession(session),
64 mCompositeStreamMap(offlineCompositeStreamMap) {}
Yin-Chia Yehb978c382019-10-30 00:22:37 -070065
Emilian Peevb2bc5a42019-11-20 16:02:14 -080066 virtual ~CameraOfflineSessionClient() {}
Yin-Chia Yehb978c382019-10-30 00:22:37 -070067
Emilian Peevd99c8ae2019-11-26 13:19:13 -080068 sp<IBinder> asBinderWrapper() override {
Emilian Peevb2bc5a42019-11-20 16:02:14 -080069 return IInterface::asBinder(this);
Yin-Chia Yehb978c382019-10-30 00:22:37 -070070 }
71
Emilian Peevd99c8ae2019-11-26 13:19:13 -080072 binder::Status disconnect() override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070073
Emilian Peevd99c8ae2019-11-26 13:19:13 -080074 status_t dump(int /*fd*/, const Vector<String16>& /*args*/) override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070075
Emilian Peevd99c8ae2019-11-26 13:19:13 -080076 status_t dumpClient(int /*fd*/, const Vector<String16>& /*args*/) override;
Emilian Peevb2bc5a42019-11-20 16:02:14 -080077
Austin Borgered99f642023-06-01 16:51:35 -070078 status_t startWatchingTags(const std::string &tags, int outFd) override;
Avichal Rakesh7e53cad2021-10-05 13:46:30 -070079 status_t stopWatchingTags(int outFd) override;
80 status_t dumpWatchedEventsToVector(std::vector<std::string> &out) override;
81
Emilian Peevd99c8ae2019-11-26 13:19:13 -080082 status_t initialize(sp<CameraProviderManager> /*manager*/,
Austin Borgered99f642023-06-01 16:51:35 -070083 const std::string& /*monitorTags*/) override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070084
Jayant Chowdhary44d5f622023-09-20 03:11:41 +000085 status_t setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal = false) override;
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -080086
Bharatt Kukreja7146ced2022-10-25 15:45:29 +000087 status_t setAutoframingOverride(uint8_t autoframingValue) override;
88
Eino-Ville Talvala305cec62020-11-12 14:18:17 -080089 bool supportsCameraMute() override;
90 status_t setCameraMute(bool enabled) override;
91
Ravneetaeb20dc2022-03-30 05:33:03 +000092 status_t setCameraServiceWatchdog(bool enabled) override;
93
Shuzhen Wang16610a62022-12-15 22:38:07 -080094 void setStreamUseCaseOverrides(
95 const std::vector<int64_t>& useCaseOverrides) override;
96
97 void clearStreamUseCaseOverrides() override;
98
Shuzhen Wangaf22e912023-04-11 16:03:17 -070099 bool supportsZoomOverride() override;
100
101 status_t setZoomOverride(int32_t zoomOverride) override;
102
Emilian Peevb2bc5a42019-11-20 16:02:14 -0800103 // permissions management
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800104 status_t startCameraOps() override;
105 status_t finishCameraOps() override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700106
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800107 // FilteredResultListener API
108 void onResultAvailable(const CaptureResult& result) override;
109
110 // NotificationListener API
111 void notifyError(int32_t errorCode, const CaptureResultExtras& resultExtras) override;
112 void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp) override;
Austin Borger4a870a32022-02-25 01:48:41 +0000113 status_t notifyActive(float maxPreviewFps) override;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700114 void notifyIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError,
115 const std::vector<hardware::CameraStreamStats>& streamStats) override;
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800116 void notifyAutoFocus(uint8_t newState, int triggerId) override;
117 void notifyAutoExposure(uint8_t newState, int triggerId) override;
118 void notifyAutoWhitebalance(uint8_t newState, int triggerId) override;
119 void notifyPrepared(int streamId) override;
120 void notifyRequestQueueEmpty() override;
121 void notifyRepeatingRequestError(long lastFrameNumber) override;
Austin Borgered99f642023-06-01 16:51:35 -0700122 status_t injectCamera(const std::string& injectedCamId,
Cliff Wud3a05312021-04-26 23:07:31 +0800123 sp<CameraProviderManager> manager) override;
124 status_t stopInjection() override;
malikakash22af94c2023-12-04 18:13:14 +0000125 status_t injectSessionParams(
126 const hardware::camera2::impl::CameraMetadataNative& sessionParams) override;
Emilian Peev4697b642019-11-19 17:11:14 -0800127
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700128private:
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800129 mutable Mutex mBinderSerializationLock;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700130
131 sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700132
133 sp<CameraOfflineSessionBase> mOfflineSession;
Emilian Peev4697b642019-11-19 17:11:14 -0800134
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800135 sp<camera2::FrameProcessorBase> mFrameProcessor;
136
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800137 // Offline composite stream map, output surface -> composite stream
Emilian Peev4697b642019-11-19 17:11:14 -0800138 KeyedVector<sp<IBinder>, sp<CompositeStream>> mCompositeStreamMap;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700139};
140
141} // namespace android
142
143#endif // ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H