1 /* 2 * Copyright (C) 2024 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_AIDLCAMERA3SHAREDDEVICE_H 18 #define ANDROID_SERVERS_AIDLCAMERA3SHAREDDEVICE_H 19 20 #include <camera/camera2/OutputConfiguration.h> 21 #include "common/FrameProcessorBase.h" 22 #include "../Camera3SharedOutputStream.h" 23 #include "AidlCamera3Device.h" 24 namespace android { 25 26 /** 27 * Shared CameraDevice for AIDL HAL devices. 28 */ 29 using ::android::camera3::Camera3SharedOutputStream; 30 class AidlCamera3SharedDevice : 31 public AidlCamera3Device, 32 public NotificationListener { 33 public: 34 static sp<AidlCamera3SharedDevice> getInstance( 35 std::shared_ptr<CameraServiceProxyWrapper>& cameraServiceProxyWrapper, 36 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils, 37 const std::string& id, bool overrideForPerfClass, int rotationOverride, 38 bool isVendorClient, bool legacyClient = false); 39 status_t initialize(sp<CameraProviderManager> manager, 40 const std::string& monitorTags) override; 41 status_t disconnectClient(int clientPid) override; 42 status_t beginConfigure() override; 43 status_t getSharedStreamId(const OutputStreamInfo &config, int *streamId) override; 44 status_t addSharedSurfaces(int streamId, 45 const std::vector<android::camera3::OutputStreamInfo> &outputInfo, 46 const std::vector<SurfaceHolder>& surfaces, 47 std::vector<int> *surfaceIds = nullptr) override; 48 status_t removeSharedSurfaces(int streamId, 49 const std::vector<size_t> &surfaceIds) override; 50 status_t setSharedStreamingRequest(const PhysicalCameraSettingsList &request, 51 const SurfaceMap &surfaceMap, int32_t *sharedReqID, int64_t *lastFrameNumber = NULL) 52 override; 53 status_t clearSharedStreamingRequest(int64_t *lastFrameNumber = NULL) override; 54 status_t setSharedCaptureRequest(const PhysicalCameraSettingsList &request, 55 const SurfaceMap &surfaceMap, int32_t *sharedReqID, int64_t *lastFrameNumber = NULL) 56 override; getSharedFrameProcessor()57 sp<camera2::FrameProcessorBase> getSharedFrameProcessor() override {return mFrameProcessor;}; 58 status_t startStreaming(const int32_t reqId, const SurfaceMap &surfaceMap, 59 int32_t *sharedReqID, int64_t *lastFrameNumber = NULL); 60 61 status_t setNotifyCallback(wp<NotificationListener> listener) override; 62 virtual void notifyError(int32_t errorCode, 63 const CaptureResultExtras &resultExtras) override; 64 virtual status_t notifyActive(float maxPreviewFps) override; 65 virtual void notifyIdle(int64_t requestCount, int64_t resultError, bool deviceError, 66 std::pair<int32_t, int32_t> mostRequestedFpsRange, 67 const std::vector<hardware::CameraStreamStats>& streamStats) override; 68 virtual void notifyShutter(const CaptureResultExtras &resultExtras, 69 nsecs_t timestamp) override; notifyRequestQueueEmpty()70 virtual void notifyRequestQueueEmpty() {}; 71 // Prepare api not supported for shared session notifyPrepared(int)72 virtual void notifyPrepared(int /*streamId*/) {}; 73 // Required only for API1 notifyAutoFocus(uint8_t,int)74 virtual void notifyAutoFocus(uint8_t /*newState*/, int /*triggerId*/) {}; notifyAutoExposure(uint8_t,int)75 virtual void notifyAutoExposure(uint8_t /*newState*/, int /*triggerId*/) {}; notifyAutoWhitebalance(uint8_t,int)76 virtual void notifyAutoWhitebalance(uint8_t /*newState*/, 77 int /*triggerId*/) {}; notifyRepeatingRequestError(long)78 virtual void notifyRepeatingRequestError(long /*lastFrameNumber*/) {}; 79 private: 80 static std::map<std::string, sp<AidlCamera3SharedDevice>> sSharedDevices; 81 static std::map<std::string, std::unordered_set<int>> sClientsPid; 82 static Mutex sSharedClientsLock; AidlCamera3SharedDevice(std::shared_ptr<CameraServiceProxyWrapper> & cameraServiceProxyWrapper,std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,const std::string & id,bool overrideForPerfClass,int rotationOverride,bool isVendorClient,bool legacyClient)83 AidlCamera3SharedDevice( 84 std::shared_ptr<CameraServiceProxyWrapper>& cameraServiceProxyWrapper, 85 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils, 86 const std::string& id, bool overrideForPerfClass, int rotationOverride, 87 bool isVendorClient, bool legacyClient) 88 : AidlCamera3Device(cameraServiceProxyWrapper, attributionAndPermissionUtils, id, 89 overrideForPerfClass, rotationOverride, isVendorClient, legacyClient), 90 mStreamingRequestId(REQUEST_ID_NONE), 91 mRequestIdCounter(0) {} 92 std::vector<OutputConfiguration> getSharedOutputConfiguration(); 93 std::vector<OutputConfiguration> mSharedOutputConfigurations; 94 std::vector<int> mSharedSurfaceIds; 95 std::vector<sp<Surface>> mSharedSurfaces; 96 std::vector<sp<BufferItemConsumer>> mOpaqueConsumers; 97 std::unordered_map<int32_t, OutputStreamInfo> mStreamInfoMap; 98 // Streaming request ID 99 int32_t mStreamingRequestId; 100 static const int32_t REQUEST_ID_NONE = -1; 101 int32_t mRequestIdCounter; 102 std::unordered_map<int, int32_t> mClientRequestIds; 103 std::unordered_map<int, SurfaceMap> mClientSurfaces; 104 std::unordered_map<int, wp<NotificationListener>> mClientListeners; 105 SurfaceMap mergeSurfaceMaps(const SurfaceMap& map1, const SurfaceMap& map2); 106 SurfaceMap removeClientSurfaceMap(const SurfaceMap& map1, const SurfaceMap& map2); 107 Mutex mSharedDeviceLock; 108 sp<camera2::FrameProcessorBase> mFrameProcessor; 109 }; // class AidlCamera3SharedDevice 110 }; // namespace android 111 #endif 112