• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_POOL_H
19 #define HISTREAMER_PLUGIN_CODEC_BUFFER_POOL_H
20 #include "v4_0/icodec_component.h"
21 #include "v4_0/codec_types.h"
22 #include "codec_buffer.h"
23 #include "foundation/osal/thread/mutex.h"
24 #include "foundation/utils/blocking_queue.h"
25 #include "plugin/common/plugin_types.h"
26 #include "plugin/common/share_allocator.h"
27 #include "plugin/common/share_memory.h"
28 
29 namespace OHOS {
30 namespace Media {
31 namespace Plugin {
32 namespace CodecAdapter {
33 
34 namespace CodecHDI = OHOS::HDI::Codec::V4_0;
35 
36 class CodecBufferPool {
37 public:
38     CodecBufferPool(sptr<CodecHDI::ICodecComponent>& compType, CodecHDI::CompVerInfo& verInfo,
39                     uint32_t portIndex, uint32_t bufferCnt);
40 
41     ~CodecBufferPool() = default;
42 
43     /**
44      * Init codec buffer and create buffer map
45      * Encoder:
46      * inBuf is surfaceBuf and allocated dynamic, outBuf is sharedBuf (READ_WRITE_TYPE)
47      * Decoder:
48      * inBuf is sharedBuf (READ_ONLY_TYPE),  outBuf is surfaceBuf and pre-allocation
49      */
50     Status UseBuffers(OHOS::Media::BlockingQueue<std::shared_ptr<Buffer>>& bufQue, MemoryType bufMemType,
51                       bool isInput, uint32_t bufferSize);
52 
53     Status FreeBuffers(); // 释放所有buffer
54 
55     uint32_t EmptyBufferCount();
56 
57     Status UseBufferDone(uint32_t bufId); // 根据该bufferId,重置omxBuffer对应的CodecBuffer
58 
59     std::shared_ptr<CodecBuffer> GetBuffer(int32_t bufferId = -1);
60 
61 private:
62     Status ConfigBufType(const MemoryType& bufMemType, bool isInput);
63 
64 private:
65     OSAL::Mutex mutex_;
66     sptr<CodecHDI::ICodecComponent> codecComp_ {nullptr};
67     CodecHDI::CompVerInfo verInfo_;
68 
69     uint32_t portIndex_;
70     OHOS::Media::BlockingQueue<uint32_t> freeBufferId_;
71     std::map<uint32_t, std::shared_ptr<CodecBuffer>> codecBufMap_;  // key is buffer id
72 };
73 } // namespace CodecAdapter
74 } // namespace Plugin
75 } // namespace Media
76 } // namespace OHOS
77 #endif // HISTREAMER_PLUGIN_CODEC_BUFFER_POOL_H
78 #endif