• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 HCODEC_HDECODER_H
17 #define HCODEC_HDECODER_H
18 
19 #include "hcodec.h"
20 
21 namespace OHOS::MediaAVCodec {
22 class HDecoder : public HCodec {
23 public:
HDecoder(OHOS::HDI::Codec::V1_0::CodecCompCapability caps,OMX_VIDEO_CODINGTYPE codingType)24     HDecoder(OHOS::HDI::Codec::V1_0::CodecCompCapability caps, OMX_VIDEO_CODINGTYPE codingType)
25         : HCodec(caps, codingType, false) {}
26 
27 private:
28     // configure
29     int32_t OnConfigure(const Format &format) override;
30     int32_t SetupPort(const Format &format);
31     int32_t UpdateInPortFormat() override;
32     int32_t UpdateOutPortFormat() override;
33     void GetCropFromOmx(uint32_t w, uint32_t h);
34     uint64_t GetUsageFromOmx();
35     int32_t OnSetOutputSurface(const sptr<Surface> &surface) override;
36     int32_t OnSetParameters(const Format &format) override;
37     GSError OnBufferReleasedByConsumer(sptr<SurfaceBuffer> &buffer);
38 
39     // start
40     int32_t AllocateBuffersOnPort(OMX_DIRTYPE portIndex) override;
41     int32_t AllocateOutputBuffersFromSurface();
42     std::shared_ptr<OHOS::HDI::Codec::V1_0::OmxCodecBuffer> SurfaceBufferToOmxBuffer(
43         const sptr<SurfaceBuffer>& surfaceBuffer);
44     int32_t SubmitAllBuffersOwnedByUs() override;
45     int32_t SubmitOutputBuffersToOmxNode() override;
46     bool ReadyToStart() override;
47 
48     // input buffer circulation
49     void OnOMXEmptyBufferDone(uint32_t bufferId, BufferOperationMode mode) override;
50 
51     // output buffer circulation
52     void OnRenderOutputBuffer(const MsgInfo &msg, BufferOperationMode mode) override;
53     int32_t NotifySurfaceToRenderOutputBuffer(BufferInfo &info);
54     void OnGetBufferFromSurface() override;
55     bool GetOneBufferFromSurface();
56 
57     // stop/release
58     void EraseBufferFromPool(OMX_DIRTYPE portIndex, size_t i) override;
59     void CancelBufferToSurface(BufferInfo& info);
60 
61 private:
62     sptr<Surface> outputSurface_;
63     BufferType outputBufferType_ = BufferType::PRESET_SURFACE_BUFFER;
64     uint32_t outBufferCnt_ = 0;
65     BufferRequestConfig requestCfg_;
66     BufferFlushConfig flushCfg_;
67     static constexpr uint32_t STRIDE_ALIGNMENT = 32;
68 };
69 } // namespace OHOS::MediaAVCodec
70 #endif // HCODEC_HDECODER_H
71