1/*
2 * Copyright (c) 2021-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 HISTREAMER_FOUNDATION_AVBUFFER_QUEUE_H
17#define HISTREAMER_FOUNDATION_AVBUFFER_QUEUE_H
18
19#include "buffer/avbuffer_queue_define.h"
20#include "buffer/avbuffer_queue_producer.h"
21#include "buffer/avbuffer_queue_consumer.h"
22#include "surface.h"
23
24namespace OHOS {
25namespace Media {
26
27class AVBufferQueue {
28public:
29    static std::shared_ptr<AVBufferQueue> Create(uint32_t size, MemoryType type = MemoryType::UNKNOWN_MEMORY,
30        const std::string& name = "", bool disableAlloc = false);
31    static std::shared_ptr<AVBufferQueue> CreateAsSurfaceProducer(
32            sptr<Surface>& surface, const std::string& name = "");
33    static std::shared_ptr<AVBufferQueue> CreateAsSurfaceConsumer(
34            sptr<Surface>& surface, const std::string& name = "");
35
36    AVBufferQueue() = default;
37    virtual ~AVBufferQueue() = default;
38    AVBufferQueue(const AVBufferQueue&) = delete;
39
40    virtual std::shared_ptr<AVBufferQueueProducer> GetLocalProducer() = 0;
41    virtual std::shared_ptr<AVBufferQueueConsumer> GetLocalConsumer() = 0;
42
43    // 跨进程对象智能指针
44    virtual sptr<AVBufferQueueProducer> GetProducer() = 0;
45    virtual sptr<AVBufferQueueConsumer> GetConsumer() = 0;
46
47    virtual sptr<Surface> GetSurfaceAsProducer() = 0;
48    virtual sptr<Surface> GetSurfaceAsConsumer() = 0;
49
50    virtual uint32_t GetQueueSize() = 0;
51    virtual Status SetQueueSize(uint32_t size) = 0;
52    virtual bool IsBufferInQueue(const std::shared_ptr<AVBuffer>& buffer) = 0;
53    virtual Status Clear() = 0;
54    virtual Status SetQueueSizeAndAttachBuffer(uint32_t size, std::shared_ptr<AVBuffer>& buffer, bool isFilled);
55};
56
57} // namespace Media
58} // namespace OHOS
59
60#endif // HISTREAMER_FOUNDATION_AVBUFFER_QUEUE_H
61