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, public std::enable_shared_from_this<HDecoder> { 23 public: HDecoder(OHOS::HDI::Codec::V2_0::CodecCompCapability caps,OMX_VIDEO_CODINGTYPE codingType)24 HDecoder(OHOS::HDI::Codec::V2_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 UpdateColorAspects() override; 34 void GetCropFromOmx(uint32_t w, uint32_t h); 35 int32_t OnSetOutputSurface(const sptr<Surface> &surface) override; 36 int32_t OnSetParameters(const Format &format) override; 37 GSError OnBufferReleasedByConsumer(sptr<SurfaceBuffer> &buffer); 38 bool UpdateConfiguredFmt(OMX_COLOR_FORMATTYPE portFmt); 39 void CombineConsumerUsage(); 40 int32_t SaveTransform(const Format &format, bool set = false); 41 int32_t SetTransform(); 42 int32_t SaveScaleMode(const Format &format, bool set = false); 43 int32_t SetScaleMode(); 44 45 // start 46 int32_t AllocateBuffersOnPort(OMX_DIRTYPE portIndex) override; 47 void UpdateFormatFromSurfaceBuffer() override; 48 int32_t AllocateOutputBuffersFromSurface(); 49 __attribute__((no_sanitize("cfi"))) int32_t SubmitAllBuffersOwnedByUs() override; 50 int32_t SubmitOutputBuffersToOmxNode() override; 51 bool ReadyToStart() override; 52 53 // input buffer circulation 54 void OnOMXEmptyBufferDone(uint32_t bufferId, BufferOperationMode mode) override; 55 56 // output buffer circulation 57 void OnRenderOutputBuffer(const MsgInfo &msg, BufferOperationMode mode) override; 58 int32_t NotifySurfaceToRenderOutputBuffer(BufferInfo &info); 59 void OnGetBufferFromSurface() override; 60 bool GetOneBufferFromSurface(); 61 uint64_t GetProducerUsage(); 62 63 // stop/release 64 void EraseBufferFromPool(OMX_DIRTYPE portIndex, size_t i) override; 65 void CancelBufferToSurface(BufferInfo &info); 66 void OnEnterUninitializedState() override; 67 68 private: 69 static constexpr uint64_t SURFACE_MODE_PRODUCER_USAGE = BUFFER_USAGE_MEM_DMA | BUFFER_USAGE_VIDEO_DECODER; 70 static constexpr uint64_t BUFFER_MODE_REQUEST_USAGE = 71 SURFACE_MODE_PRODUCER_USAGE | BUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_MMZ_CACHE; 72 sptr<Surface> outputSurface_; 73 uint32_t outBufferCnt_ = 0; 74 BufferFlushConfig flushCfg_; 75 GraphicTransformType originalTransform_; 76 GraphicTransformType transform_ = GRAPHIC_ROTATE_NONE; 77 std::optional<ScalingMode> scaleMode_; 78 }; 79 } // namespace OHOS::MediaAVCodec 80 #endif // HCODEC_HDECODER_H 81