• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <mutex>
22 
23 namespace OHOS::Camera {
24 class BufferManager {
25 public:
26 
27     // get a pointer of BufferManager
28     static BufferManager* GetInstance();
29 
30     // generate a random id for buffer pool.
31     uint64_t GenerateBufferPoolId();
32 
33     // get a buffer pool from id.
34     std::shared_ptr<IBufferPool> GetBufferPool(uint64_t id);
35 
36     void EraseBufferPoolMapById(uint64_t id);
37 
38 private:
39     BufferManager() = default;
40     BufferManager(const BufferManager&);
41     BufferManager& operator=(const BufferManager&);
42     BufferManager(BufferManager&&);
43     BufferManager& operator=(BufferManager&&);
44 
45     ~BufferManager() = default;
46 
47     std::mutex lock_;
48     std::map<int64_t, std::weak_ptr<IBufferPool>> bufferPoolMap_;
49 };
50 } // namespace OHOS::Camera
51 #endif
52