1 /* 2 * Copyright (C) 2022 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 HDI_BUFFER_MGR_H 17 #define HDI_BUFFER_MGR_H 18 19 #include <mutex> 20 #include <list> 21 #include <vector> 22 #include <condition_variable> 23 #include <gst/gst.h> 24 #include <OMX_Core.h> 25 #include <OMX_Component.h> 26 #include "nocopyable.h" 27 #include "i_codec_buffer_mgr.h" 28 #include "codec_component_type.h" 29 #include "codec_component_if.h" 30 #include "buffer_type_meta.h" 31 #include "codec_omx_ext.h" 32 33 namespace OHOS { 34 namespace Media { 35 struct HdiBufferWrap { 36 intptr_t buf; 37 OmxCodecBuffer hdiBuffer; 38 }; 39 class HdiBufferMgr : public NoCopyable, public ICodecBufferMgr { 40 public: 41 HdiBufferMgr(); 42 virtual ~HdiBufferMgr() override; 43 virtual void Init(CodecComponentType *handle, int32_t index, const CompVerInfo &verInfo); 44 virtual int32_t Start(); 45 AllocateBuffers()46 int32_t AllocateBuffers() override 47 { 48 return GST_CODEC_OK; 49 } 50 UseBuffers(std::vector<GstBuffer * > buffers)51 int32_t UseBuffers(std::vector<GstBuffer *> buffers) override 52 { 53 (void)buffers; 54 return GST_CODEC_OK; 55 } 56 PushBuffer(GstBuffer * buffer)57 int32_t PushBuffer(GstBuffer *buffer) override 58 { 59 (void)buffer; 60 return GST_CODEC_OK; 61 } 62 PullBuffer(GstBuffer ** buffer)63 int32_t PullBuffer(GstBuffer **buffer) override 64 { 65 (void)buffer; 66 return GST_CODEC_OK; 67 } 68 FreeBuffers()69 int32_t FreeBuffers() override 70 { 71 return GST_CODEC_OK; 72 } 73 Preprocessing()74 virtual int32_t Preprocessing() 75 { 76 return GST_CODEC_OK; 77 } 78 CodecBufferAvailable(const OmxCodecBuffer * buffer)79 virtual int32_t CodecBufferAvailable(const OmxCodecBuffer *buffer) 80 { 81 (void)buffer; 82 return GST_CODEC_OK; 83 } 84 GetWaitDisPlayBufNum()85 virtual uint32_t GetWaitDisPlayBufNum() 86 { 87 return 0; 88 } 89 SetOutputPool(GstBufferPool * pool)90 virtual void SetOutputPool(GstBufferPool *pool) 91 { 92 (void)pool; 93 } 94 95 virtual int32_t Flush(bool enable) override; 96 virtual int32_t Stop(bool isFormatChange); 97 virtual void WaitFlushed(); 98 void BufferReleased(); 99 100 protected: 101 void FreeCodecBuffers(); 102 void ClearCodingBuffers(); 103 std::atomic<bool> bufferReleased_ = false; 104 bool isFlushing_ = false; 105 bool isFlushed_ = false; 106 bool isStart_ = false; 107 bool isFormatChange_ = false; 108 int32_t mPortIndex_ = 0; 109 CompVerInfo verInfo_ = {}; 110 std::mutex mutex_; 111 std::condition_variable flushCond_; 112 std::condition_variable bufferCond_; 113 std::condition_variable freeCond_; 114 std::condition_variable preBufferCond_; 115 OMX_PARAM_PORTDEFINITIONTYPE mPortDef_ = {}; 116 CodecComponentType *handle_ = nullptr; 117 std::list<std::shared_ptr<HdiBufferWrap>> availableBuffers_; 118 std::list<std::pair<std::shared_ptr<HdiBufferWrap>, GstBuffer *>> codingBuffers_; 119 std::vector<std::shared_ptr<HdiBufferWrap>> PreUseAshareMems(std::vector<GstBuffer *> &buffers); 120 int32_t UseHdiBuffers(std::vector<std::shared_ptr<HdiBufferWrap>> &buffers); 121 virtual std::shared_ptr<HdiBufferWrap> GetCodecBuffer(GstBuffer *buffer); 122 virtual void UpdateCodecMeta(GstBufferTypeMeta *bufferType, std::shared_ptr<HdiBufferWrap> &codecBuffer); 123 void NotifyAvailable(); 124 void SetFlagToBuffer(GstBuffer *buffer, const uint32_t &flag); 125 }; 126 } // namespace Media 127 } // namespace OHOS 128 #endif // HDI_BUFFER_MGR_H 129