blob: 77de874ff904e28d43d88314713112b8cb74cc70 [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
Jayant Chowdhary81d81b02024-02-15 19:13:39 +000020#include <android/hardware/ICameraService.h>
Yin-Chia Yehb978c382019-10-30 00:22:37 -070021#include <android/hardware/camera2/BnCameraOfflineSession.h>
22#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
Emilian Peevd99c8ae2019-11-26 13:19:13 -080023#include "common/FrameProcessorBase.h"
24#include "common/CameraDeviceBase.h"
Yin-Chia Yehb978c382019-10-30 00:22:37 -070025#include "CameraService.h"
Emilian Peev4697b642019-11-19 17:11:14 -080026#include "CompositeStream.h"
Yin-Chia Yehb978c382019-10-30 00:22:37 -070027
28namespace android {
29
30using android::hardware::camera2::ICameraDeviceCallbacks;
Emilian Peev4697b642019-11-19 17:11:14 -080031using camera3::CompositeStream;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070032
Emilian Peevb2bc5a42019-11-20 16:02:14 -080033// Client for offline session. Note that offline session client does not affect camera service's
34// client arbitration logic. It is camera HAL's decision to decide whether a normal camera
35// client is conflicting with existing offline client(s).
36// The other distinctive difference between offline clients and normal clients is that normal
37// clients are created through ICameraService binder calls, while the offline session client
38// is created through ICameraDeviceUser::switchToOffline call.
Yin-Chia Yehb978c382019-10-30 00:22:37 -070039class CameraOfflineSessionClient :
Emilian Peevb2bc5a42019-11-20 16:02:14 -080040 public CameraService::BasicClient,
Emilian Peevd99c8ae2019-11-26 13:19:13 -080041 public hardware::camera2::BnCameraOfflineSession,
42 public camera2::FrameProcessorBase::FilteredListener,
43 public NotificationListener
Yin-Chia Yehb978c382019-10-30 00:22:37 -070044{
45public:
46 CameraOfflineSessionClient(
47 const sp<CameraService>& cameraService,
48 sp<CameraOfflineSessionBase> session,
Emilian Peev4697b642019-11-19 17:11:14 -080049 const KeyedVector<sp<IBinder>, sp<CompositeStream>>& offlineCompositeStreamMap,
Yin-Chia Yehb978c382019-10-30 00:22:37 -070050 const sp<ICameraDeviceCallbacks>& remoteCallback,
Austin Borger249e6592024-03-10 22:28:11 -070051 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,
Austin Borgered99f642023-06-01 16:51:35 -070052 const std::string& clientPackageName,
53 const std::optional<std::string>& clientFeatureId,
54 const std::string& cameraIdStr, int cameraFacing, int sensorOrientation,
Yin-Chia Yehb978c382019-10-30 00:22:37 -070055 int clientPid, uid_t clientUid, int servicePid) :
Emilian Peevb2bc5a42019-11-20 16:02:14 -080056 CameraService::BasicClient(
57 cameraService,
58 IInterface::asBinder(remoteCallback),
Austin Borger249e6592024-03-10 22:28:11 -070059 attributionAndPermissionUtils,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080060 // (v)ndk doesn't have offline session support
61 clientPackageName, /*overridePackageName*/false, clientFeatureId,
Austin Borger18b30a72022-10-27 12:20:29 -070062 cameraIdStr, cameraFacing, sensorOrientation, clientPid, clientUid, servicePid,
Jayant Chowdhary81d81b02024-02-15 19:13:39 +000063 hardware::ICameraService::ROTATION_OVERRIDE_NONE),
Emilian Peev4697b642019-11-19 17:11:14 -080064 mRemoteCallback(remoteCallback), mOfflineSession(session),
65 mCompositeStreamMap(offlineCompositeStreamMap) {}
Yin-Chia Yehb978c382019-10-30 00:22:37 -070066
Emilian Peevb2bc5a42019-11-20 16:02:14 -080067 virtual ~CameraOfflineSessionClient() {}
Yin-Chia Yehb978c382019-10-30 00:22:37 -070068
Emilian Peevd99c8ae2019-11-26 13:19:13 -080069 sp<IBinder> asBinderWrapper() override {
Emilian Peevb2bc5a42019-11-20 16:02:14 -080070 return IInterface::asBinder(this);
Yin-Chia Yehb978c382019-10-30 00:22:37 -070071 }
72
Emilian Peevd99c8ae2019-11-26 13:19:13 -080073 binder::Status disconnect() override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070074
Emilian Peevd99c8ae2019-11-26 13:19:13 -080075 status_t dump(int /*fd*/, const Vector<String16>& /*args*/) override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070076
Emilian Peevd99c8ae2019-11-26 13:19:13 -080077 status_t dumpClient(int /*fd*/, const Vector<String16>& /*args*/) override;
Emilian Peevb2bc5a42019-11-20 16:02:14 -080078
Austin Borgered99f642023-06-01 16:51:35 -070079 status_t startWatchingTags(const std::string &tags, int outFd) override;
Avichal Rakesh7e53cad2021-10-05 13:46:30 -070080 status_t stopWatchingTags(int outFd) override;
81 status_t dumpWatchedEventsToVector(std::vector<std::string> &out) override;
82
Emilian Peevd99c8ae2019-11-26 13:19:13 -080083 status_t initialize(sp<CameraProviderManager> /*manager*/,
Austin Borgered99f642023-06-01 16:51:35 -070084 const std::string& /*monitorTags*/) override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070085
Jayant Chowdhary44d5f622023-09-20 03:11:41 +000086 status_t setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal = false) override;
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -080087
Bharatt Kukreja7146ced2022-10-25 15:45:29 +000088 status_t setAutoframingOverride(uint8_t autoframingValue) override;
89
Eino-Ville Talvala305cec62020-11-12 14:18:17 -080090 bool supportsCameraMute() override;
91 status_t setCameraMute(bool enabled) override;
92
Ravneetaeb20dc2022-03-30 05:33:03 +000093 status_t setCameraServiceWatchdog(bool enabled) override;
94
Shuzhen Wang16610a62022-12-15 22:38:07 -080095 void setStreamUseCaseOverrides(
96 const std::vector<int64_t>& useCaseOverrides) override;
97
98 void clearStreamUseCaseOverrides() override;
99
Shuzhen Wangaf22e912023-04-11 16:03:17 -0700100 bool supportsZoomOverride() override;
101
102 status_t setZoomOverride(int32_t zoomOverride) override;
103
Emilian Peevb2bc5a42019-11-20 16:02:14 -0800104 // permissions management
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800105 status_t startCameraOps() override;
106 status_t finishCameraOps() override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700107
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800108 // FilteredResultListener API
109 void onResultAvailable(const CaptureResult& result) override;
110
111 // NotificationListener API
112 void notifyError(int32_t errorCode, const CaptureResultExtras& resultExtras) override;
113 void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp) override;
Austin Borger4a870a32022-02-25 01:48:41 +0000114 status_t notifyActive(float maxPreviewFps) override;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700115 void notifyIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700116 std::pair<int32_t, int32_t> mostRequestedFpsRange,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700117 const std::vector<hardware::CameraStreamStats>& streamStats) override;
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800118 void notifyAutoFocus(uint8_t newState, int triggerId) override;
119 void notifyAutoExposure(uint8_t newState, int triggerId) override;
120 void notifyAutoWhitebalance(uint8_t newState, int triggerId) override;
121 void notifyPrepared(int streamId) override;
122 void notifyRequestQueueEmpty() override;
123 void notifyRepeatingRequestError(long lastFrameNumber) override;
Austin Borgered99f642023-06-01 16:51:35 -0700124 status_t injectCamera(const std::string& injectedCamId,
Cliff Wud3a05312021-04-26 23:07:31 +0800125 sp<CameraProviderManager> manager) override;
126 status_t stopInjection() override;
malikakash22af94c2023-12-04 18:13:14 +0000127 status_t injectSessionParams(
128 const hardware::camera2::impl::CameraMetadataNative& sessionParams) override;
Emilian Peev4697b642019-11-19 17:11:14 -0800129
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700130private:
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800131 mutable Mutex mBinderSerializationLock;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700132
133 sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700134
135 sp<CameraOfflineSessionBase> mOfflineSession;
Emilian Peev4697b642019-11-19 17:11:14 -0800136
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800137 sp<camera2::FrameProcessorBase> mFrameProcessor;
138
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800139 // Offline composite stream map, output surface -> composite stream
Emilian Peev4697b642019-11-19 17:11:14 -0800140 KeyedVector<sp<IBinder>, sp<CompositeStream>> mCompositeStreamMap;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700141};
142
143} // namespace android
144
145#endif // ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H