1 /* 2 * Copyright (c) 2023-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_CAMERA_H_CAMERA_DEVICE_MANAGER_H 17 #define OHOS_CAMERA_H_CAMERA_DEVICE_MANAGER_H 18 19 #include <refbase.h> 20 #include "hcamera_device.h" 21 #include "camera_util.h" 22 #include "mem_mgr_client.h" 23 #include "safe_map.h" 24 25 namespace OHOS { 26 namespace CameraStandard { 27 class HCameraDeviceManager : public RefBase { 28 public: 29 ~HCameraDeviceManager(); 30 /** 31 * @brief Get camera device manager instance. 32 * 33 * @return Returns pointer to camera device manager instance. 34 */ 35 static sptr<HCameraDeviceManager> &GetInstance(); 36 37 /** 38 * @brief Add opened device in camera device manager. 39 * 40 * @param device Device that have been turned on. 41 * @param pid Pid for opening the device. 42 */ 43 void AddDevice(pid_t pid, sptr<HCameraDevice> device); 44 45 /** 46 * @brief remove camera in camera device manager. 47 * 48 * @param device Device that have been turned off. 49 */ 50 void RemoveDevice(); 51 52 /** 53 * @brief Get cameras by active process pid. 54 * 55 * @param pid Pid of active process. 56 */ 57 sptr<HCameraDevice> GetCameraByPid(pid_t pid); 58 59 /** 60 * @brief Get process pid device manager instance. 61 * 62 * @return Returns pointer to camera device manager instance. 63 */ 64 pid_t GetActiveClient(); 65 66 void SetStateOfACamera(std::string cameraId, int32_t state); 67 68 SafeMap<std::string, int32_t> &GetCameraStateOfASide(); 69 70 /** 71 * @brief remove camera in camera device manager. 72 * 73 * @param camerasNeedEvict Devices that need to be shut down. 74 * @param cameraIdRequestOpen device is requested to turn on. 75 */ 76 bool GetConflictDevices(sptr<HCameraDevice> &camerasNeedEvict, sptr<HCameraDevice> cameraIdRequestOpen); 77 private: 78 HCameraDeviceManager(); 79 SafeMap<pid_t, sptr<HCameraDevice>> pidToCameras_; 80 SafeMap<std::string, int32_t> stateOfACamera_; 81 static sptr<HCameraDeviceManager> cameraDeviceManager_; 82 static std::mutex instanceMutex_; 83 std::mutex mapMutex_; 84 std::string GetACameraId(); 85 int32_t GetAdjForCameraState(std::string cameraId); 86 bool isAllowOpen(pid_t activeClient); 87 }; 88 } // namespace CameraStandard 89 } // namespace OHOS 90 #endif // OHOS_CAMERA_H_CAMERA_DEVICE_MANAGER_H