xref: /aosp_15_r20/frameworks/av/services/camera/libcameraservice/api2/CameraOfflineSessionClient.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1 /*
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/ICameraService.h>
21 #include <android/hardware/camera2/BnCameraOfflineSession.h>
22 #include <android/hardware/camera2/ICameraDeviceCallbacks.h>
23 #include "common/FrameProcessorBase.h"
24 #include "common/CameraDeviceBase.h"
25 #include "CameraService.h"
26 #include "CompositeStream.h"
27 
28 namespace android {
29 
30 using android::hardware::camera2::ICameraDeviceCallbacks;
31 using camera3::CompositeStream;
32 
33 #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
34 typedef uint64_t SurfaceKey;
35 #else
36 typedef sp<IBinder> SurfaceKey;
37 #endif
38 
39 // Client for offline session. Note that offline session client does not affect camera service's
40 // client arbitration logic. It is camera HAL's decision to decide whether a normal camera
41 // client is conflicting with existing offline client(s).
42 // The other distinctive difference between offline clients and normal clients is that normal
43 // clients are created through ICameraService binder calls, while the offline session client
44 // is created through ICameraDeviceUser::switchToOffline call.
45 class CameraOfflineSessionClient :
46         public CameraService::BasicClient,
47         public hardware::camera2::BnCameraOfflineSession,
48         public camera2::FrameProcessorBase::FilteredListener,
49         public NotificationListener
50 {
51 public:
CameraOfflineSessionClient(const sp<CameraService> & cameraService,sp<CameraOfflineSessionBase> session,const KeyedVector<SurfaceKey,sp<CompositeStream>> & offlineCompositeStreamMap,const sp<ICameraDeviceCallbacks> & remoteCallback,std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,const AttributionSourceState & clientAttribution,int callingPid,const std::string & cameraIdStr,int cameraFacing,int sensorOrientation,int servicePid,bool sharedMode)52     CameraOfflineSessionClient(
53             const sp<CameraService>& cameraService, sp<CameraOfflineSessionBase> session,
54             const KeyedVector<SurfaceKey, sp<CompositeStream>>& offlineCompositeStreamMap,
55             const sp<ICameraDeviceCallbacks>& remoteCallback,
56             std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,
57             const AttributionSourceState& clientAttribution, int callingPid,
58             const std::string& cameraIdStr, int cameraFacing, int sensorOrientation, int servicePid,
59             bool sharedMode)
60         : CameraService::BasicClient(cameraService, IInterface::asBinder(remoteCallback),
61                                      attributionAndPermissionUtils,
62                                      // (v)ndk doesn't have offline session support
63                                      clientAttribution, callingPid, /*overridePackageName*/ false,
64                                      cameraIdStr, cameraFacing, sensorOrientation, servicePid,
65                                      hardware::ICameraService::ROTATION_OVERRIDE_NONE, sharedMode),
66         mRemoteCallback(remoteCallback),
67         mOfflineSession(session),
68         mCompositeStreamMap(offlineCompositeStreamMap) {}
69 
~CameraOfflineSessionClient()70     virtual ~CameraOfflineSessionClient() {}
71 
asBinderWrapper()72     sp<IBinder> asBinderWrapper() override {
73         return IInterface::asBinder(this);
74     }
75 
76     binder::Status disconnect() override;
77 
78     status_t dump(int /*fd*/, const Vector<String16>& /*args*/) override;
79 
80     status_t dumpClient(int /*fd*/, const Vector<String16>& /*args*/) override;
81 
82     status_t startWatchingTags(const std::string &tags, int outFd) override;
83     status_t stopWatchingTags(int outFd) override;
84     status_t dumpWatchedEventsToVector(std::vector<std::string> &out) override;
85 
86     status_t initialize(sp<CameraProviderManager> /*manager*/,
87             const std::string& /*monitorTags*/) override;
88 
89     status_t setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal = false) override;
90 
91     status_t setAutoframingOverride(uint8_t autoframingValue) override;
92 
93     bool supportsCameraMute() override;
94     status_t setCameraMute(bool enabled) override;
95 
96     status_t setCameraServiceWatchdog(bool enabled) override;
97 
98     void setStreamUseCaseOverrides(
99             const std::vector<int64_t>& useCaseOverrides) override;
100 
101     void clearStreamUseCaseOverrides() override;
102 
103     bool supportsZoomOverride() override;
104 
105     status_t setZoomOverride(int32_t zoomOverride) override;
106 
107     // permissions management
108     status_t notifyCameraOpening() override;
109     status_t notifyCameraClosing() override;
110 
111     // FilteredResultListener API
112     void onResultAvailable(const CaptureResult& result) override;
113 
114     // NotificationListener API
115     void notifyError(int32_t errorCode, const CaptureResultExtras& resultExtras) override;
116     void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp) override;
117     status_t notifyActive(float maxPreviewFps) override;
118     void notifyIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError,
119             std::pair<int32_t, int32_t> mostRequestedFpsRange,
120             const std::vector<hardware::CameraStreamStats>& streamStats) override;
121     void notifyAutoFocus(uint8_t newState, int triggerId) override;
122     void notifyAutoExposure(uint8_t newState, int triggerId) override;
123     void notifyAutoWhitebalance(uint8_t newState, int triggerId) override;
124     void notifyPrepared(int streamId) override;
125     void notifyRequestQueueEmpty() override;
126     void notifyRepeatingRequestError(long lastFrameNumber) override;
127     status_t injectCamera(const std::string& injectedCamId,
128             sp<CameraProviderManager> manager) override;
129     void notifyClientSharedAccessPriorityChanged(bool primaryClient) override;
130     status_t stopInjection() override;
131     status_t injectSessionParams(
132         const hardware::camera2::impl::CameraMetadataNative& sessionParams) override;
133 
134 private:
135     mutable Mutex mBinderSerializationLock;
136 
137     sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
138 
139     sp<CameraOfflineSessionBase> mOfflineSession;
140 
141     sp<camera2::FrameProcessorBase> mFrameProcessor;
142 
143     // Offline composite stream map, output surface -> composite stream
144     KeyedVector<SurfaceKey, sp<CompositeStream>> mCompositeStreamMap;
145 };
146 
147 } // namespace android
148 
149 #endif // ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H
150