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_IBUFFER_POOL_H
17 #define HOS_CAMERA_IBUFFER_POOL_H
18 
19 #include "ibuffer.h"
20 #include <map>
21 
22 namespace OHOS::Camera {
23 class IBufferPool {
24 public:
~IBufferPool()25     virtual ~IBufferPool() {}
26 
27     // init a buffer pool, bufferSourceType indicates where buffers come from.
28     virtual RetCode Init(const uint32_t width,
29                          const uint32_t height,
30                          const uint64_t usage,
31                          const uint32_t bufferFormat,
32                          const uint32_t count,
33                          const int32_t bufferSourceType) = 0;
34 
35     // add buffer to buffer pool, only for external source.
36     virtual RetCode AddBuffer(std::shared_ptr<IBuffer>& buffer) = 0;
37 
38     /* request a idle buffer from pool.
39      * timeout < 0, wait until there is idle buffer in pool.
40      * timeout = 0, no wait, could return null.
41      * timeout > 0, wait for timeout seconds, if timeout return null.
42      */
43     virtual std::shared_ptr<IBuffer> AcquireBuffer(int timeout) = 0;
AcquireBuffer()44     std::shared_ptr<IBuffer> AcquireBuffer()
45     {
46         return AcquireBuffer(0);
47     }
48 
49     // return a buffer to pool.
50     virtual RetCode ReturnBuffer(std::shared_ptr<IBuffer>& buffer) = 0;
51 
52     // enable tracking buffers of pool
53     virtual void EnableTracking(const int32_t id) = 0;
54     virtual void SetId(const int64_t id) = 0;
55     virtual void NotifyStop() = 0;
56     virtual void NotifyStart() = 0;
57     virtual void ClearBuffers() = 0;
58     virtual uint32_t GetIdleBufferCount() = 0;
59 };
60 } // namespace OHOS::Camera
61 
62 #endif
63