blob: 574ff9a3114352bf8d8a8ccec926de8285f81242 [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(
Austin Borger2e772b82024-10-11 16:09:57 -070047 const sp<CameraService>& cameraService, 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 Borger2e772b82024-10-11 16:09:57 -070051 const AttributionSourceState& clientAttribution, int callingPid,
52 const std::string& cameraIdStr, int cameraFacing, int sensorOrientation, int servicePid)
53 : CameraService::BasicClient(cameraService, IInterface::asBinder(remoteCallback),
54 attributionAndPermissionUtils,
55 // (v)ndk doesn't have offline session support
56 clientAttribution, callingPid, /*overridePackageName*/ false,
57 cameraIdStr, cameraFacing, sensorOrientation, servicePid,
58 hardware::ICameraService::ROTATION_OVERRIDE_NONE),
59 mRemoteCallback(remoteCallback),
60 mOfflineSession(session),
61 mCompositeStreamMap(offlineCompositeStreamMap) {}
Yin-Chia Yehb978c382019-10-30 00:22:37 -070062
Emilian Peevb2bc5a42019-11-20 16:02:14 -080063 virtual ~CameraOfflineSessionClient() {}
Yin-Chia Yehb978c382019-10-30 00:22:37 -070064
Emilian Peevd99c8ae2019-11-26 13:19:13 -080065 sp<IBinder> asBinderWrapper() override {
Emilian Peevb2bc5a42019-11-20 16:02:14 -080066 return IInterface::asBinder(this);
Yin-Chia Yehb978c382019-10-30 00:22:37 -070067 }
68
Emilian Peevd99c8ae2019-11-26 13:19:13 -080069 binder::Status disconnect() override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070070
Emilian Peevd99c8ae2019-11-26 13:19:13 -080071 status_t dump(int /*fd*/, const Vector<String16>& /*args*/) override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070072
Emilian Peevd99c8ae2019-11-26 13:19:13 -080073 status_t dumpClient(int /*fd*/, const Vector<String16>& /*args*/) override;
Emilian Peevb2bc5a42019-11-20 16:02:14 -080074
Austin Borgered99f642023-06-01 16:51:35 -070075 status_t startWatchingTags(const std::string &tags, int outFd) override;
Avichal Rakesh7e53cad2021-10-05 13:46:30 -070076 status_t stopWatchingTags(int outFd) override;
77 status_t dumpWatchedEventsToVector(std::vector<std::string> &out) override;
78
Emilian Peevd99c8ae2019-11-26 13:19:13 -080079 status_t initialize(sp<CameraProviderManager> /*manager*/,
Austin Borgered99f642023-06-01 16:51:35 -070080 const std::string& /*monitorTags*/) override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -070081
Jayant Chowdhary44d5f622023-09-20 03:11:41 +000082 status_t setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal = false) override;
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -080083
Bharatt Kukreja7146ced2022-10-25 15:45:29 +000084 status_t setAutoframingOverride(uint8_t autoframingValue) override;
85
Eino-Ville Talvala305cec62020-11-12 14:18:17 -080086 bool supportsCameraMute() override;
87 status_t setCameraMute(bool enabled) override;
88
Ravneetaeb20dc2022-03-30 05:33:03 +000089 status_t setCameraServiceWatchdog(bool enabled) override;
90
Shuzhen Wang16610a62022-12-15 22:38:07 -080091 void setStreamUseCaseOverrides(
92 const std::vector<int64_t>& useCaseOverrides) override;
93
94 void clearStreamUseCaseOverrides() override;
95
Shuzhen Wangaf22e912023-04-11 16:03:17 -070096 bool supportsZoomOverride() override;
97
98 status_t setZoomOverride(int32_t zoomOverride) override;
99
Emilian Peevb2bc5a42019-11-20 16:02:14 -0800100 // permissions management
Austin Borgera0c61f12024-10-11 13:38:35 -0700101 status_t notifyCameraOpening() override;
102 status_t notifyCameraClosing() override;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700103
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800104 // FilteredResultListener API
105 void onResultAvailable(const CaptureResult& result) override;
106
107 // NotificationListener API
108 void notifyError(int32_t errorCode, const CaptureResultExtras& resultExtras) override;
109 void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp) override;
Austin Borger4a870a32022-02-25 01:48:41 +0000110 status_t notifyActive(float maxPreviewFps) override;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700111 void notifyIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError,
Eino-Ville Talvalaffc186b2024-04-09 18:10:47 -0700112 std::pair<int32_t, int32_t> mostRequestedFpsRange,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700113 const std::vector<hardware::CameraStreamStats>& streamStats) override;
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800114 void notifyAutoFocus(uint8_t newState, int triggerId) override;
115 void notifyAutoExposure(uint8_t newState, int triggerId) override;
116 void notifyAutoWhitebalance(uint8_t newState, int triggerId) override;
117 void notifyPrepared(int streamId) override;
118 void notifyRequestQueueEmpty() override;
119 void notifyRepeatingRequestError(long lastFrameNumber) override;
Austin Borgered99f642023-06-01 16:51:35 -0700120 status_t injectCamera(const std::string& injectedCamId,
Cliff Wud3a05312021-04-26 23:07:31 +0800121 sp<CameraProviderManager> manager) override;
122 status_t stopInjection() override;
malikakash22af94c2023-12-04 18:13:14 +0000123 status_t injectSessionParams(
124 const hardware::camera2::impl::CameraMetadataNative& sessionParams) override;
Emilian Peev4697b642019-11-19 17:11:14 -0800125
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700126private:
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800127 mutable Mutex mBinderSerializationLock;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700128
129 sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700130
131 sp<CameraOfflineSessionBase> mOfflineSession;
Emilian Peev4697b642019-11-19 17:11:14 -0800132
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800133 sp<camera2::FrameProcessorBase> mFrameProcessor;
134
Emilian Peevd99c8ae2019-11-26 13:19:13 -0800135 // Offline composite stream map, output surface -> composite stream
Emilian Peev4697b642019-11-19 17:11:14 -0800136 KeyedVector<sp<IBinder>, sp<CompositeStream>> mCompositeStreamMap;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700137};
138
139} // namespace android
140
141#endif // ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H