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 clientPackageName, clientFeatureId, 58 cameraIdStr, cameraFacing, sensorOrientation, clientPid, clientUid, servicePid), 59 mRemoteCallback(remoteCallback), mOfflineSession(session), 60 mCompositeStreamMap(offlineCompositeStreamMap) {} 61 ~CameraOfflineSessionClient()62 virtual ~CameraOfflineSessionClient() {} 63 asBinderWrapper()64 sp<IBinder> asBinderWrapper() override { 65 return IInterface::asBinder(this); 66 } 67 68 binder::Status disconnect() override; 69 70 status_t dump(int /*fd*/, const Vector<String16>& /*args*/) override; 71 72 status_t dumpClient(int /*fd*/, const Vector<String16>& /*args*/) override; 73 74 status_t initialize(sp<CameraProviderManager> /*manager*/, 75 const String8& /*monitorTags*/) override; 76 77 status_t setRotateAndCropOverride(uint8_t rotateAndCrop) override; 78 79 bool supportsCameraMute() override; 80 status_t setCameraMute(bool enabled) override; 81 82 // permissions management 83 status_t startCameraOps() override; 84 status_t finishCameraOps() override; 85 86 // FilteredResultListener API 87 void onResultAvailable(const CaptureResult& result) override; 88 89 // NotificationListener API 90 void notifyError(int32_t errorCode, const CaptureResultExtras& resultExtras) override; 91 void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp) override; 92 status_t notifyActive() override; 93 void notifyIdle(int64_t requestCount, int64_t resultErrorCount, bool deviceError, 94 const std::vector<hardware::CameraStreamStats>& streamStats) override; 95 void notifyAutoFocus(uint8_t newState, int triggerId) override; 96 void notifyAutoExposure(uint8_t newState, int triggerId) override; 97 void notifyAutoWhitebalance(uint8_t newState, int triggerId) override; 98 void notifyPrepared(int streamId) override; 99 void notifyRequestQueueEmpty() override; 100 void notifyRepeatingRequestError(long lastFrameNumber) override; 101 102 private: 103 mutable Mutex mBinderSerializationLock; 104 105 sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback; 106 107 sp<CameraOfflineSessionBase> mOfflineSession; 108 109 sp<camera2::FrameProcessorBase> mFrameProcessor; 110 111 // Offline composite stream map, output surface -> composite stream 112 KeyedVector<sp<IBinder>, sp<CompositeStream>> mCompositeStreamMap; 113 }; 114 115 } // namespace android 116 117 #endif // ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H 118