1 /*
2  * Copyright (C) 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 AV_CODEC_BUFFER_INFO_H
17 #define AV_CODEC_BUFFER_INFO_H
18 
19 #include <atomic>
20 #include <memory>
21 #include <vector>
22 
23 #include "audio_common_info.h"
24 #include "avcodec_common.h"
25 #include "buffer/avsharedmemorybase.h"
26 #include "nocopyable.h"
27 
28 namespace OHOS {
29 namespace MediaAVCodec {
30 class AudioBufferInfo : public NoCopyable {
31 public:
32     AudioBufferInfo(const uint32_t bufferSize, const std::string_view &name, const uint32_t metaSize = 0);
33 
34     ~AudioBufferInfo();
35 
36     std::shared_ptr<Media::AVSharedMemoryBase> GetBuffer() const noexcept;
37 
38     std::shared_ptr<Media::AVSharedMemoryBase> GetMetadata() const noexcept;
39 
40     bool IsHasMetaData() const noexcept;
41 
42     bool ResetBuffer();
43 
44     bool SetBufferOwned();
45 
46     bool IsAvailable() const noexcept;
47 
48     BufferStatus GetStatus() const noexcept;
49 
50     bool CheckIsEos() const noexcept;
51 
52     void SetEos(bool eos);
53 
54     void SetBufferAttr(const AVCodecBufferInfo &attr);
55 
56     AVCodecBufferInfo GetBufferAttr() const noexcept;
57 
58     AVCodecBufferFlag GetFlag() const noexcept;
59 
60     bool CheckIsFirstFrame() const noexcept;
61 
62     void SetFirstFrame() noexcept;
63 
64     bool CheckIsUsing() const noexcept;
65 
66     void SetUsing() noexcept;
67 
68     uint32_t GetBufferSize() const noexcept;
69 
70 private:
71     bool isHasMeta_;
72     bool isEos_;
73     bool isFirstFrame_;
74     std::atomic<bool> isUsing;
75     std::atomic<BufferStatus> status_;
76     uint32_t bufferSize_;
77     uint32_t metaSize_;
78     std::string_view name_;
79     std::shared_ptr<Media::AVSharedMemoryBase> buffer_;
80     std::shared_ptr<Media::AVSharedMemoryBase> metadata_;
81     AVCodecBufferInfo info_;
82     AVCodecBufferFlag flag_;
83 };
84 } // namespace MediaAVCodec
85 } // namespace OHOS
86 #endif