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 // 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. 39 class CameraOfflineSessionClient : 40 public CameraService::BasicClient, 41 public hardware::camera2::BnCameraOfflineSession, 42 public camera2::FrameProcessorBase::FilteredListener, 43 public NotificationListener 44 { 45 public: CameraOfflineSessionClient(const sp<CameraService> & cameraService,sp<CameraOfflineSessionBase> session,const KeyedVector<sp<IBinder>,sp<CompositeStream>> & offlineCompositeStreamMap,const sp<ICameraDeviceCallbacks> & remoteCallback,std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,const std::string & clientPackageName,const std::optional<std::string> & clientFeatureId,const std::string & cameraIdStr,int cameraFacing,int sensorOrientation,int clientPid,uid_t clientUid,int servicePid)46 CameraOfflineSessionClient( 47 const sp<CameraService>& cameraService, 48 sp<CameraOfflineSessionBase> session, 49 const KeyedVector<sp<IBinder>, sp<CompositeStream>>& offlineCompositeStreamMap, 50 const sp<ICameraDeviceCallbacks>& remoteCallback, 51 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils, 52 const std::string& clientPackageName, 53 const std::optional<std::string>& clientFeatureId, 54 const std::string& cameraIdStr, int cameraFacing, int sensorOrientation, 55 int clientPid, uid_t clientUid, int servicePid) : 56 CameraService::BasicClient( 57 cameraService, 58 IInterface::asBinder(remoteCallback), 59 attributionAndPermissionUtils, 60 // (v)ndk doesn't have offline session support 61 clientPackageName, /*overridePackageName*/false, clientFeatureId, 62 cameraIdStr, cameraFacing, sensorOrientation, clientPid, clientUid, servicePid, 63 hardware::ICameraService::ROTATION_OVERRIDE_NONE), 64 mRemoteCallback(remoteCallback), mOfflineSession(session), 65 mCompositeStreamMap(offlineCompositeStreamMap) {} 66 ~CameraOfflineSessionClient()67 virtual ~CameraOfflineSessionClient() {} 68 asBinderWrapper()69 sp<IBinder> asBinderWrapper() override { 70 return IInterface::asBinder(this); 71 } 72 73 binder::Status disconnect() override; 74 75 status_t dump(int /*fd*/, const Vector<String16>& /*args*/) override; 76 77 status_t dumpClient(int /*fd*/, const Vector<String16>& /*args*/) override; 78 79 status_t startWatchingTags(const std::string &tags, int outFd) override; 80 status_t stopWatchingTags(int outFd) override; 81 status_t dumpWatchedEventsToVector(std::vector<std::string> &out) override; 82 83 status_t initialize(sp<CameraProviderManager> /*manager*/, 84 const std::string& /*monitorTags*/) override; 85 86 status_t setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal = false) override; 87 88 status_t setAutoframingOverride(uint8_t autoframingValue) override; 89 90 bool supportsCameraMute() override; 91 status_t setCameraMute(bool enabled) override; 92 93 status_t setCameraServiceWatchdog(bool enabled) override; 94 95 void setStreamUseCaseOverrides( 96 const std::vector<int64_t>& useCaseOverrides) override; 97 98 void clearStreamUseCaseOverrides() override; 99 100 bool supportsZoomOverride() override; 101 102 status_t setZoomOverride(int32_t zoomOverride) override; 103 104 // permissions management 105 status_t startCameraOps() override; 106 status_t finishCameraOps() override; 107 108 // 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; 114 status_t notifyActive(float maxPreviewFps) override; 115 void notifyIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError, 116 std::pair<int32_t, int32_t> mostRequestedFpsRange, 117 const std::vector<hardware::CameraStreamStats>& streamStats) override; 118 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; 124 status_t injectCamera(const std::string& injectedCamId, 125 sp<CameraProviderManager> manager) override; 126 status_t stopInjection() override; 127 status_t injectSessionParams( 128 const hardware::camera2::impl::CameraMetadataNative& sessionParams) override; 129 130 private: 131 mutable Mutex mBinderSerializationLock; 132 133 sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback; 134 135 sp<CameraOfflineSessionBase> mOfflineSession; 136 137 sp<camera2::FrameProcessorBase> mFrameProcessor; 138 139 // Offline composite stream map, output surface -> composite stream 140 KeyedVector<sp<IBinder>, sp<CompositeStream>> mCompositeStreamMap; 141 }; 142 143 } // namespace android 144 145 #endif // ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H 146