1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2022-2023 Shenzhen Kaihong DID Co., Ltd.. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#ifndef I_CODEC_BUFFER_H 17094332d3Sopenharmony_ci#define I_CODEC_BUFFER_H 18094332d3Sopenharmony_ci#include <OMX_Component.h> 19094332d3Sopenharmony_ci#include <OMX_Core.h> 20094332d3Sopenharmony_ci#include <OMX_Types.h> 21094332d3Sopenharmony_ci#include <buffer_handle.h> 22094332d3Sopenharmony_ci#include <buffer_handle_utils.h> 23094332d3Sopenharmony_ci#include <memory> 24094332d3Sopenharmony_ci#include <refbase.h> 25094332d3Sopenharmony_ci#include "codec_component_type.h" 26094332d3Sopenharmony_ci#include "codec_omx_ext.h" 27094332d3Sopenharmony_ciconstexpr uint32_t TIME_WAIT_MS = 10; 28094332d3Sopenharmony_cinamespace OHOS { 29094332d3Sopenharmony_cinamespace Codec { 30094332d3Sopenharmony_cinamespace Omx { 31094332d3Sopenharmony_cistruct DynamicBuffer { 32094332d3Sopenharmony_ci int32_t type; 33094332d3Sopenharmony_ci BufferHandle *bufferHandle; 34094332d3Sopenharmony_ci 35094332d3Sopenharmony_ci DynamicBuffer() : type(0), bufferHandle(nullptr) 36094332d3Sopenharmony_ci {} 37094332d3Sopenharmony_ci ~DynamicBuffer() 38094332d3Sopenharmony_ci { 39094332d3Sopenharmony_ci type = 0; 40094332d3Sopenharmony_ci if (bufferHandle != nullptr) { 41094332d3Sopenharmony_ci FreeBufferHandle(bufferHandle); 42094332d3Sopenharmony_ci } 43094332d3Sopenharmony_ci bufferHandle = nullptr; 44094332d3Sopenharmony_ci } 45094332d3Sopenharmony_ci}; 46094332d3Sopenharmony_ci 47094332d3Sopenharmony_ciclass ICodecBuffer : public RefBase { 48094332d3Sopenharmony_cipublic: 49094332d3Sopenharmony_ci explicit ICodecBuffer(struct OmxCodecBuffer &codecBuffer); 50094332d3Sopenharmony_ci virtual ~ICodecBuffer() override; 51094332d3Sopenharmony_ci static sptr<ICodecBuffer> CreateCodeBuffer(struct OmxCodecBuffer &codecBuffer); 52094332d3Sopenharmony_ci static sptr<ICodecBuffer> AllocateCodecBuffer(struct OmxCodecBuffer &codecBuffer); 53094332d3Sopenharmony_ci virtual int32_t FillOmxBuffer(struct OmxCodecBuffer &codecBuffer, OMX_BUFFERHEADERTYPE &omxBuffer); 54094332d3Sopenharmony_ci virtual int32_t EmptyOmxBuffer(struct OmxCodecBuffer &codecBuffer, OMX_BUFFERHEADERTYPE &omxBuffer); 55094332d3Sopenharmony_ci virtual int32_t FreeBuffer(struct OmxCodecBuffer &codecBuffer) = 0; 56094332d3Sopenharmony_ci virtual int32_t EmptyOmxBufferDone(OMX_BUFFERHEADERTYPE &omxBuffer); 57094332d3Sopenharmony_ci virtual int32_t FillOmxBufferDone(OMX_BUFFERHEADERTYPE &omxBuffer); 58094332d3Sopenharmony_ci virtual uint8_t *GetBuffer() = 0; 59094332d3Sopenharmony_ci struct OmxCodecBuffer &GetCodecBuffer(); 60094332d3Sopenharmony_ci void SetBufferId(int32_t bufferId); 61094332d3Sopenharmony_ci 62094332d3Sopenharmony_ciprotected: 63094332d3Sopenharmony_ci ICodecBuffer() 64094332d3Sopenharmony_ci {} 65094332d3Sopenharmony_ci virtual bool CheckInvalid(struct OmxCodecBuffer &codecBuffer); 66094332d3Sopenharmony_ci int32_t SyncWait(int fd, uint32_t timeout); 67094332d3Sopenharmony_ciprotected: 68094332d3Sopenharmony_ci struct OmxCodecBuffer codecBuffer_; 69094332d3Sopenharmony_ci}; 70094332d3Sopenharmony_ci} // namespace Omx 71094332d3Sopenharmony_ci} // namespace Codec 72094332d3Sopenharmony_ci} // namespace OHOS 73094332d3Sopenharmony_ci#endif