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::unique_ptr<String16> & clientFeatureId,const String8 & cameraIdStr,int cameraFacing,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::unique_ptr<String16>& clientFeatureId, 52 const String8& cameraIdStr, int cameraFacing, 53 int clientPid, uid_t clientUid, int servicePid) : 54 CameraService::BasicClient( 55 cameraService, 56 IInterface::asBinder(remoteCallback), 57 clientPackageName, clientFeatureId, 58 cameraIdStr, cameraFacing, 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 // permissions management 80 status_t startCameraOps() override; 81 status_t finishCameraOps() override; 82 83 // FilteredResultListener API 84 void onResultAvailable(const CaptureResult& result) override; 85 86 // NotificationListener API 87 void notifyError(int32_t errorCode, const CaptureResultExtras& resultExtras) override; 88 void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp) override; 89 void notifyIdle() override; 90 void notifyAutoFocus(uint8_t newState, int triggerId) override; 91 void notifyAutoExposure(uint8_t newState, int triggerId) override; 92 void notifyAutoWhitebalance(uint8_t newState, int triggerId) override; 93 void notifyPrepared(int streamId) override; 94 void notifyRequestQueueEmpty() override; 95 void notifyRepeatingRequestError(long lastFrameNumber) override; 96 97 private: 98 mutable Mutex mBinderSerializationLock; 99 100 sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback; 101 102 sp<CameraOfflineSessionBase> mOfflineSession; 103 104 sp<camera2::FrameProcessorBase> mFrameProcessor; 105 106 // Offline composite stream map, output surface -> composite stream 107 KeyedVector<sp<IBinder>, sp<CompositeStream>> mCompositeStreamMap; 108 }; 109 110 } // namespace android 111 112 #endif // ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H 113