• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Shenzhen Kaihong DID 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 I_CODEC_BUFFER_H
17 #define I_CODEC_BUFFER_H
18 #include <OMX_Component.h>
19 #include <OMX_Core.h>
20 #include <OMX_Types.h>
21 #include <buffer_handle.h>
22 #include <buffer_handle_utils.h>
23 #include <memory>
24 #include <refbase.h>
25 #include "codec_omx_ext.h"
26 #include "v1_0/codec_types.h"
27 using OHOS::HDI::Codec::V1_0::OmxCodecBuffer;
28 constexpr uint32_t TIME_WAIT_MS = 10;
29 namespace OHOS {
30 namespace Codec {
31 namespace Omx {
32 struct DynamicBuffer {
33     int32_t type;
34     BufferHandle *bufferHandle;
35 
DynamicBufferDynamicBuffer36     DynamicBuffer() : type(0), bufferHandle(nullptr)
37     {}
~DynamicBufferDynamicBuffer38     ~DynamicBuffer()
39     {
40         type = 0;
41         if (bufferHandle != nullptr) {
42             FreeBufferHandle(bufferHandle);
43         }
44         bufferHandle = nullptr;
45     }
46 };
47 
48 class ICodecBuffer : public RefBase {
49 public:
50     ICodecBuffer(struct OmxCodecBuffer &codecBuffer);
51     virtual ~ICodecBuffer();
52     sptr<ICodecBuffer> static CreateCodeBuffer(struct OmxCodecBuffer &codecBuffer);
53     sptr<ICodecBuffer> static AllocateCodecBuffer(struct OmxCodecBuffer &codecBuffer);
54     virtual int32_t FillOmxBuffer(struct OmxCodecBuffer &codecBuffer, OMX_BUFFERHEADERTYPE &omxBuffer);
55     virtual int32_t EmptyOmxBuffer(struct OmxCodecBuffer &codecBuffer, OMX_BUFFERHEADERTYPE &omxBuffer);
56     virtual int32_t FreeBuffer(struct OmxCodecBuffer &codecBuffer) = 0;
57     virtual int32_t EmptyOmxBufferDone(OMX_BUFFERHEADERTYPE &omxBuffer);
58     virtual int32_t FillOmxBufferDone(OMX_BUFFERHEADERTYPE &omxBuffer);
59     virtual uint8_t *GetBuffer() = 0;
60     struct OmxCodecBuffer &GetCodecBuffer();
61     void SetBufferId(int32_t bufferId);
62 
63 protected:
ICodecBuffer()64     ICodecBuffer()
65     {}
66     virtual bool CheckInvalid(struct OmxCodecBuffer &codecBuffer);
67     int32_t SyncWait(int fd, uint32_t timeout);
68 protected:
69     struct OmxCodecBuffer codecBuffer_;
70 };
71 }  // namespace Omx
72 }  // namespace Codec
73 }  // namespace OHOS
74 #endif