• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 IMAGE_DECODER_H
17 #define IMAGE_DECODER_H
18 
19  #include "hardware/imagecodec/image_codec.h"
20 
21 namespace OHOS::ImagePlugin {
22 class ImageDecoder : public ImageCodec {
23 public:
24     ImageDecoder();
25 private:
26     // configure
27     int32_t OnConfigure(const Format &format) override;
28     int32_t SetupPort(const Format &format);
29     int32_t UpdateInPortFormat() override;
30     int32_t UpdateOutPortFormat() override;
31     bool UpdateConfiguredFmt(OMX_COLOR_FORMATTYPE portFmt);
32     void UpdateColorAspects() override;
33     void UpdateDisplaySizeByCrop();
34     int32_t ReConfigureOutputBufferCnt() override;
35     uint64_t OnGetOutputBufferUsage() override;
36     int32_t OnSetOutputBuffer(sptr<SurfaceBuffer> output) override;
37     bool OnGetPackedInputCapability() override;
38     bool OnSetPackedInputFlag(bool flag) override;
39 
40     // start
41     int32_t AllocateBuffersOnPort(OMX_DIRTYPE portIndex, bool isOutputPortSettingChanged) override;
42     void UpdateFormatFromSurfaceBuffer() override;
43     int32_t SubmitAllBuffersOwnedByUs() override;
44     int32_t SubmitOutputBuffersToOmxNode() override;
45     bool ReadyToStart() override;
46 
47     // input buffer circulation
48     void OnOMXEmptyBufferDone(uint32_t bufferId, BufferOperationMode mode) override;
49 
50     // output buffer circulation
51     uint64_t GetProducerUsage();
52 
53     // stop/release
54     void EraseBufferFromPool(OMX_DIRTYPE portIndex, size_t i) override;
55 private:
56     static constexpr uint64_t BUFFER_MODE_REQUEST_USAGE =
57         BUFFER_USAGE_MEM_DMA | BUFFER_USAGE_VIDEO_DECODER | BUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_MMZ_CACHE;
58     bool enableHeifGrid_ = false;
59     sptr<SurfaceBuffer> outputBuffer_;
60 };
61 } // namespace OHOS::ImagePlugin
62 
63 #endif // IMAGE_DECODER_H