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 85 virtual int32_t Flush(bool enable) override; 86 virtual int32_t Stop(bool isFormatChange); 87 virtual void WaitFlushed(); 88 89 protected: 90 void FreeCodecBuffers(); 91 bool isFlushing_ = false; 92 bool isFlushed_ = false; 93 bool isStart_ = false; 94 bool isFormatChange_ = false; 95 int32_t mPortIndex_ = 0; 96 CompVerInfo verInfo_ = {}; 97 std::mutex mutex_; 98 std::condition_variable flushCond_; 99 std::condition_variable bufferCond_; 100 std::condition_variable freeCond_; 101 OMX_PARAM_PORTDEFINITIONTYPE mPortDef_ = {}; 102 CodecComponentType *handle_ = nullptr; 103 std::list<std::shared_ptr<HdiBufferWrap>> availableBuffers_; 104 std::list<std::pair<std::shared_ptr<HdiBufferWrap>, GstBuffer *>> codingBuffers_; 105 std::vector<std::shared_ptr<HdiBufferWrap>> PreUseAshareMems(std::vector<GstBuffer *> &buffers); 106 int32_t UseHdiBuffers(std::vector<std::shared_ptr<HdiBufferWrap>> &buffers); 107 virtual std::shared_ptr<HdiBufferWrap> GetCodecBuffer(GstBuffer *buffer); 108 virtual void UpdateCodecMeta(GstBufferTypeMeta *bufferType, std::shared_ptr<HdiBufferWrap> &codecBuffer); 109 void NotifyAvailable(); 110 void SetFlagToBuffer(GstBuffer *buffer, const uint32_t &flag); 111 }; 112 } // namespace Media 113 } // namespace OHOS 114 #endif // HDI_BUFFER_MGR_H 115