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 OnGetPackedInputFlag() override; 38 39 // start 40 int32_t AllocateBuffersOnPort(OMX_DIRTYPE portIndex, bool isOutputPortSettingChanged) override; 41 void UpdateFormatFromSurfaceBuffer() override; 42 int32_t SubmitAllBuffersOwnedByUs() override; 43 int32_t SubmitOutputBuffersToOmxNode() override; 44 bool ReadyToStart() override; 45 46 // input buffer circulation 47 void OnOMXEmptyBufferDone(uint32_t bufferId, BufferOperationMode mode) override; 48 49 // output buffer circulation 50 uint64_t GetProducerUsage(); 51 52 // stop/release 53 void EraseBufferFromPool(OMX_DIRTYPE portIndex, size_t i) override; 54 private: 55 static constexpr uint64_t BUFFER_MODE_REQUEST_USAGE = 56 BUFFER_USAGE_MEM_DMA | BUFFER_USAGE_VIDEO_DECODER | BUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_MMZ_CACHE; 57 bool enableHeifGrid_ = false; 58 sptr<SurfaceBuffer> outputBuffer_; 59 }; 60 } // namespace OHOS::ImagePlugin 61 62 #endif // IMAGE_DECODER_H