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