1 /* 2 * Copyright (c) 2025-2025 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_CAPTURE_SESSION_MANAGER_H 17 #define OHOS_CAMERA_H_CAPTURE_SESSION_MANAGER_H 18 19 #include <iterator> 20 #include <list> 21 #include <memory> 22 #include <mutex> 23 #include <cstdint> 24 #include <unordered_map> 25 26 #include "camera_util.h" 27 #include "refbase.h" 28 #include "singleton.h" 29 30 namespace OHOS { 31 namespace CameraStandard { 32 class HCaptureSession; 33 class HMechSession; 34 class SessionGroup : public std::list<sptr<HCaptureSession>> {}; 35 class HCameraSessionManager : public Singleton<HCameraSessionManager> { 36 public: 37 size_t GetTotalSessionSize(); 38 size_t GetGroupCount(); 39 size_t GetSessionSize(pid_t pid); 40 std::list<sptr<HCaptureSession>> GetTotalSession(); 41 std::list<sptr<HCaptureSession>> GetGroupSessions(pid_t pid); 42 std::vector<sptr<HCaptureSession>> GetUserSessions(int32_t userId); 43 sptr<HCaptureSession> GetGroupDefaultSession(pid_t pid); 44 sptr<HMechSession> GetMechSession(int32_t userId); 45 CamServiceError AddSession(sptr<HCaptureSession> session); 46 CamServiceError AddSessionForPC(sptr<HCaptureSession> session); 47 CamServiceError AddMechSession(int32_t userId, sptr<HMechSession> mechSession); 48 void RemoveSession(sptr<HCaptureSession> session); 49 void RemoveMechSession(int32_t userId); 50 void RemoveGroup(pid_t pid); 51 void PreemptOverflowSessions(pid_t pid); 52 53 private: 54 void RemoveGroupNoLock(std::unordered_map<pid_t, SessionGroup>::iterator mapIt); 55 56 std::mutex totalSessionMapMutex_; 57 std::unordered_map<pid_t, SessionGroup> totalSessionMap_; 58 std::mutex mechMapMutex_; 59 std::unordered_map<int32_t, sptr<HMechSession>> mechSessionMap_; 60 }; 61 } // namespace CameraStandard 62 } // namespace OHOS 63 64 #endif