1 /* 2 * Copyright (c) 2021 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 HOS_CAMERA_BUFFER_MANAGER_H 17 #define HOS_CAMERA_BUFFER_MANAGER_H 18 19 #include "ibuffer_pool.h" 20 #include <map> 21 #include <memory> 22 #include <mutex> 23 24 namespace OHOS::Camera { 25 class BufferManager { 26 public: 27 28 // get a pointer of BufferManager 29 static BufferManager* GetInstance(); 30 31 // generate a random id for buffer pool. 32 int64_t GenerateBufferPoolId(); 33 34 // get a buffer pool from id. 35 std::shared_ptr<IBufferPool> GetBufferPool(int64_t id); 36 37 private: 38 BufferManager() = default; 39 BufferManager(const BufferManager&); 40 BufferManager& operator=(const BufferManager&); 41 BufferManager(BufferManager&&); 42 BufferManager& operator=(BufferManager&&); 43 44 ~BufferManager() = default; 45 46 std::mutex lock_; 47 std::map<int64_t, std::weak_ptr<IBufferPool>> bufferPoolMap_; 48 }; 49 } // namespace OHOS::Camera 50 #endif 51