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 CODEC_SHARE_BUFFER_H
17#define CODEC_SHARE_BUFFER_H
18#include <ashmem.h>
19#include <memory>
20#include "icodec_buffer.h"
21
22namespace OHOS {
23namespace Codec {
24namespace Omx {
25class CodecShareBuffer : ICodecBuffer {
26public:
27    ~CodecShareBuffer();
28    OHOS::sptr<ICodecBuffer> static Create(struct OmxCodecBuffer &codecBuffer);
29    OHOS::sptr<ICodecBuffer> static Allocate(struct OmxCodecBuffer &codecBuffer);
30    int32_t FillOmxBuffer(struct OmxCodecBuffer &codecBuffer, OMX_BUFFERHEADERTYPE &omxBuffer) override;
31    int32_t EmptyOmxBuffer(struct OmxCodecBuffer &codecBuffer, OMX_BUFFERHEADERTYPE &omxBuffer) override;
32    int32_t FreeBuffer(struct OmxCodecBuffer &codecBuffer) override;
33    int32_t EmptyOmxBufferDone(OMX_BUFFERHEADERTYPE &omxBuffer) override;
34    int32_t FillOmxBufferDone(OMX_BUFFERHEADERTYPE &omxBuffer) override;
35    void SetAshMem(std::shared_ptr<OHOS::Ashmem> shMem);
36    uint8_t *GetBuffer() override;
37
38protected:
39    CodecShareBuffer(struct OmxCodecBuffer &codecBuffer);
40    bool CheckInvalid(struct OmxCodecBuffer &codecBuffer) override;
41
42private:
43    std::shared_ptr<OHOS::Ashmem> shMem_;
44};
45}  // namespace Omx
46}  // namespace Codec
47}  // namespace OHOS
48#endif