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_STREAM_OPERATOR_MANAGER_H 17 #define OHOS_CAMERA_H_STREAM_OPERATOR_MANAGER_H 18 19 #include <refbase.h> 20 #include <set> 21 #include <mutex> 22 #include "safe_map.h" 23 namespace OHOS { 24 namespace CameraStandard { 25 class HStreamOperator; 26 class HStreamOperatorManager : public RefBase { 27 public: 28 29 ~HStreamOperatorManager(); 30 31 static sptr<HStreamOperatorManager> &GetInstance(); 32 33 void AddStreamOperator(sptr<HStreamOperator> hStreamOperator); 34 35 void RemoveStreamOperator(int32_t& hStreamOperatorId); 36 37 void UpdateStreamOperator(int32_t& hStreamOperatorId); 38 39 int32_t GetOfflineOutputSize(); 40 41 std::vector<sptr<HStreamOperator>> GetStreamOperatorByPid(pid_t pidRequest); 42 43 private: 44 HStreamOperatorManager(); 45 std::mutex mapMutex_; 46 static sptr<HStreamOperatorManager> streamOperatorManager_; 47 std::map<int32_t, sptr<HStreamOperator>> streamOperatorManagerMap_; 48 static std::mutex instanceMutex_; 49 std::atomic<int32_t> streamOperatorIdGenerator_ = -1; 50 GenerateStreamOperatorId()51 inline int32_t GenerateStreamOperatorId() 52 { 53 streamOperatorIdGenerator_.fetch_add(1); 54 if (streamOperatorIdGenerator_ == INT32_MAX) { 55 streamOperatorIdGenerator_ = 0; 56 } 57 return streamOperatorIdGenerator_; 58 } 59 }; 60 } // namespace CameraStandard 61 } // namespace OHOS 62 #endif // OHOS_CAMERA_H_STREAM_OPERATOR_MANAGER_H 63