1 /*
2  * Copyright (c) 2023-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 #if defined(VIDEO_SUPPORT)
17 
18 #ifndef HISTREAMER_PLUGIN_CODEC_BUFFER_H
19 #define HISTREAMER_PLUGIN_CODEC_BUFFER_H
20 
21 #include "codec_component_type.h"
22 #include "codec_omx_ext.h"
23 #include "plugin/common/plugin_buffer.h"
24 #include "plugin/common/share_memory.h"
25 
26 namespace OHOS {
27 namespace Media {
28 namespace Plugin {
29 namespace CodecAdapter {
30 class CodecBuffer {
31 public:
32     CodecBuffer(std::shared_ptr<Buffer>& buffer, CompVerInfo& verInfo,
33         bool isInput, uint32_t bufferSize, MemoryType bufMemType);
34 
35     ~CodecBuffer() = default;
36 
37     std::shared_ptr<OmxCodecBuffer> GetOmxBuffer();
38 
39     uint32_t GetBufferId() const;
40 
41     Status Copy(const std::shared_ptr<Plugin::Buffer>& pluginBuffer);
42 
43     Status Rebind(const std::shared_ptr<Plugin::Buffer>& pluginBuffer); // 重新申请内存时, CodecBuffer都要重新创建
44 
45     Status Unbind(std::shared_ptr<Plugin::Buffer>& buffer, const OmxCodecBuffer* omxBuffer);
46 
47 private:
48     void Init(bool isInput, uint32_t bufferSize, MemoryType bufMemType);
49 
50     std::shared_ptr<Buffer> buffer_;
51     CompVerInfo verInfo_ {};
52     std::shared_ptr<Memory> memory_;
53     std::shared_ptr<OmxCodecBuffer> omxBuffer_;
54 };
55 } // namespace CodecAdapter
56 } // namespace Plugin
57 } // namespace Media
58 } // namespace OHOS
59 #endif // HISTREAMER_PLUGIN_CODEC_BUFFER_H
60 #endif