• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/camera2/BnCameraOfflineSession.h>
21 #include <android/hardware/camera2/ICameraDeviceCallbacks.h>
22 #include "common/FrameProcessorBase.h"
23 #include "common/CameraDeviceBase.h"
24 #include "CameraService.h"
25 #include "CompositeStream.h"
26 
27 namespace android {
28 
29 using android::hardware::camera2::ICameraDeviceCallbacks;
30 using camera3::CompositeStream;
31 
32 // 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.
38 class CameraOfflineSessionClient :
39         public CameraService::BasicClient,
40         public hardware::camera2::BnCameraOfflineSession,
41         public camera2::FrameProcessorBase::FilteredListener,
42         public NotificationListener
43 {
44 public:
CameraOfflineSessionClient(const sp<CameraService> & cameraService,sp<CameraOfflineSessionBase> session,const KeyedVector<sp<IBinder>,sp<CompositeStream>> & offlineCompositeStreamMap,const sp<ICameraDeviceCallbacks> & remoteCallback,const String16 & clientPackageName,const std::optional<String16> & clientFeatureId,const String8 & cameraIdStr,int cameraFacing,int sensorOrientation,int clientPid,uid_t clientUid,int servicePid)45     CameraOfflineSessionClient(
46             const sp<CameraService>& cameraService,
47             sp<CameraOfflineSessionBase> session,
48             const KeyedVector<sp<IBinder>, sp<CompositeStream>>& offlineCompositeStreamMap,
49             const sp<ICameraDeviceCallbacks>& remoteCallback,
50             const String16& clientPackageName,
51             const std::optional<String16>& clientFeatureId,
52             const String8& cameraIdStr, int cameraFacing, int sensorOrientation,
53             int clientPid, uid_t clientUid, int servicePid) :
54             CameraService::BasicClient(
55                     cameraService,
56                     IInterface::asBinder(remoteCallback),
57                     // (v)ndk doesn't have offline session support
58                     clientPackageName, /*overridePackageName*/false, clientFeatureId,
59                     cameraIdStr, cameraFacing, sensorOrientation, clientPid, clientUid, servicePid,
60                     /*overrideToPortrait*/false),
61             mRemoteCallback(remoteCallback), mOfflineSession(session),
62             mCompositeStreamMap(offlineCompositeStreamMap) {}
63 
~CameraOfflineSessionClient()64     virtual ~CameraOfflineSessionClient() {}
65 
asBinderWrapper()66     sp<IBinder> asBinderWrapper() override {
67         return IInterface::asBinder(this);
68     }
69 
70     binder::Status disconnect() override;
71 
72     status_t dump(int /*fd*/, const Vector<String16>& /*args*/) override;
73 
74     status_t dumpClient(int /*fd*/, const Vector<String16>& /*args*/) override;
75 
76     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 
80     status_t initialize(sp<CameraProviderManager> /*manager*/,
81             const String8& /*monitorTags*/) override;
82 
83     status_t setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal = false) override;
84 
85     status_t setAutoframingOverride(uint8_t autoframingValue) override;
86 
87     bool supportsCameraMute() override;
88     status_t setCameraMute(bool enabled) override;
89 
90     status_t setCameraServiceWatchdog(bool enabled) override;
91 
92     void setStreamUseCaseOverrides(
93             const std::vector<int64_t>& useCaseOverrides) override;
94 
95     void clearStreamUseCaseOverrides() override;
96 
97     bool supportsZoomOverride() override;
98 
99     status_t setZoomOverride(int32_t zoomOverride) override;
100 
101     // permissions management
102     status_t startCameraOps() override;
103     status_t finishCameraOps() override;
104 
105     // FilteredResultListener API
106     void onResultAvailable(const CaptureResult& result) override;
107 
108     // NotificationListener API
109     void notifyError(int32_t errorCode, const CaptureResultExtras& resultExtras) override;
110     void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp) override;
111     status_t notifyActive(float maxPreviewFps) override;
112     void notifyIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError,
113             const std::vector<hardware::CameraStreamStats>& streamStats) override;
114     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;
120     status_t injectCamera(const String8& injectedCamId,
121             sp<CameraProviderManager> manager) override;
122     status_t stopInjection() override;
123 
124 private:
125     mutable Mutex mBinderSerializationLock;
126 
127     sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
128 
129     sp<CameraOfflineSessionBase> mOfflineSession;
130 
131     sp<camera2::FrameProcessorBase> mFrameProcessor;
132 
133     // Offline composite stream map, output surface -> composite stream
134     KeyedVector<sp<IBinder>, sp<CompositeStream>> mCompositeStreamMap;
135 };
136 
137 } // namespace android
138 
139 #endif // ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H
140