1 /* 2 * Copyright (c) 2018-2021, Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 //! 23 //! \file encode_hevc_basic_feature.h 24 //! \brief Defines the common interface for encode hevc basic feature 25 //! 26 #ifndef __ENCODE_HEVC_BASIC_FEATURE_H__ 27 #define __ENCODE_HEVC_BASIC_FEATURE_H__ 28 29 #include <deque> 30 #include "encode_basic_feature.h" 31 #include "codec_def_encode_hevc.h" 32 #include "encode_hevc_reference_frames.h" 33 #include "media_hevc_feature_defs.h" 34 #include "mhw_vdbox_vdenc_itf.h" 35 #include "mhw_vdbox_hcp_itf.h" 36 #include "encode_mem_compression.h" 37 #include "encode_hevc_basic_feature_422.h" 38 namespace encode 39 { 40 #define CODECHAL_HEVC_VDENC_LCU_SIZE 64 41 #define CODECHAL_HEVC_MIN_LCU_SIZE 16 42 #define CODECHAL_HEVC_MIN_CU_SIZE 8 43 #define CODECHAL_HEVC_MIN_TILE_SIZE 128 44 #define CODECHAL_ENCODE_HEVC_MIN_ICQ_QUALITYFACTOR 1 45 #define CODECHAL_ENCODE_HEVC_MAX_ICQ_QUALITYFACTOR 51 46 47 class HevcBasicFeature : public EncodeBasicFeature, public mhw::vdbox::vdenc::Itf::ParSetting, public mhw::vdbox::hcp::Itf::ParSetting 48 { 49 public: 50 HevcBasicFeature(EncodeAllocator *allocator, 51 CodechalHwInterfaceNext *hwInterface, 52 TrackedBuffer *trackedBuf, 53 RecycleResource *recycleBuf, 54 void *constSettings = nullptr) : EncodeBasicFeature(allocator,hwInterface,trackedBuf,recycleBuf)55 EncodeBasicFeature(allocator, hwInterface, trackedBuf, recycleBuf){ m_constSettings = constSettings;}; 56 57 virtual ~HevcBasicFeature(); 58 59 virtual MOS_STATUS Init(void *setting) override; 60 61 virtual MOS_STATUS Update(void *params) override; 62 63 virtual uint32_t GetProfileLevelMaxFrameSize() override; 64 65 MOS_STATUS GetSurfaceMmcInfo(PMOS_SURFACE surface, MOS_MEMCOMP_STATE &mmcState, uint32_t &compressionFormat) const; 66 67 MHW_SETPAR_DECL_HDR(VDENC_PIPE_MODE_SELECT); 68 69 MHW_SETPAR_DECL_HDR(VDENC_SRC_SURFACE_STATE); 70 71 MHW_SETPAR_DECL_HDR(VDENC_REF_SURFACE_STATE); 72 73 MHW_SETPAR_DECL_HDR(VDENC_DS_REF_SURFACE_STATE); 74 75 MHW_SETPAR_DECL_HDR(VDENC_PIPE_BUF_ADDR_STATE); 76 77 MHW_SETPAR_DECL_HDR(VDENC_CMD1); 78 79 MHW_SETPAR_DECL_HDR(VDENC_CMD2); 80 81 MHW_SETPAR_DECL_HDR(HCP_PIC_STATE); 82 83 MHW_SETPAR_DECL_HDR(HEVC_VP9_RDOQ_STATE); 84 85 MHW_SETPAR_DECL_HDR(HCP_SURFACE_STATE); 86 87 MHW_SETPAR_DECL_HDR(HCP_SLICE_STATE); 88 89 EncodeMemComp *m_mmcState = nullptr; 90 91 static constexpr uint32_t m_maxSliceQP = 52; //!< Max QP 92 static constexpr uint32_t m_maxLCUSize = 64; //!< Max LCU size 64 93 static constexpr uint32_t m_qpNum = 52; //!< Number of QP values 94 static constexpr uint32_t m_maxSyncDepth = 10; 95 96 // Parameters passed from application 97 PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS m_hevcSeqParams = nullptr; //!< Pointer to sequence parameter 98 PCODEC_HEVC_ENCODE_PICTURE_PARAMS m_hevcPicParams = nullptr; //!< Pointer to picture parameter 99 PCODEC_HEVC_ENCODE_SLICE_PARAMS m_hevcSliceParams = nullptr; //!< Pointer to slice parameter 100 PCODECHAL_HEVC_IQ_MATRIX_PARAMS m_hevcIqMatrixParams = nullptr; //!< Pointer to IQ matrix parameter 101 HevcReferenceFrames m_ref = {}; //! Reference List 102 103 uint32_t m_lambdaType = 1; 104 std::vector<double> m_qpFactors; 105 106 uint32_t m_numTiles = 1; 107 uint32_t m_curNumSlices = 0; 108 109 bool m_lastSliceInTile = false; 110 111 uint32_t m_maxTileNumber = 0; 112 uint32_t m_picWidthInMinLCU = 0; 113 uint32_t m_picHeightInMinLCU = 0; 114 uint32_t m_widthAlignedMaxLCU = 0; 115 uint32_t m_heightAlignedMaxLCU = 0; 116 uint32_t m_sizeOfMvTemporalBuffer = 0; 117 bool m_hevcRDOQPerfDisabled = false; 118 PMOS_RESOURCE m_resMvTemporalBuffer = nullptr; //!< Pointer to MOS_RESOURCE of MvTemporal Buffer 119 120 uint32_t m_sizeOfSseSrcPixelRowStoreBufferPerLcu = 0; //!< Size of SSE row store buffer per LCU 121 // VDENC Display interface related 122 uint8_t m_slotForRecNotFiltered = 0; 123 bool m_enableLBCOnly = false; 124 bool m_enablePartialFrameUpdate = false; 125 bool m_pakOnlyPass = false; 126 bool m_captureModeEnable = false; //!< Enable Capture mode with display 127 bool m_hevcVdencRoundingPrecisionEnabled = true; //!< Roinding Precision enabled 128 uint8_t m_roundingIntra = 0; 129 uint8_t m_roundingInter = 0; 130 bool m_useDefaultRoundingForHcpSliceState = false; //!< use default rounding for HCP_SLICE_STATE 131 bool m_hevcVdencWeightedPredEnabled = false; 132 uint32_t m_prevStoreData = -1; // Change to -1 since FrameIdx starts from 0; Legacy path initialized to be 0 since FrameIdx starts from 1; 133 uint32_t m_vdencBatchBufferPerSliceVarSize[ENCODE_HEVC_VDENC_NUM_MAX_SLICES] = { 0 }; //!< VDEnc batch buffer slice size array 134 uint32_t m_vdencBatchBufferPerSlicePart2Start[ENCODE_HEVC_VDENC_NUM_MAX_SLICES] = {0}; //!< VDEnc batch buffer slice size array 135 uint32_t m_vdencBatchBufferPerSlicePart2Size[ENCODE_HEVC_VDENC_NUM_MAX_SLICES] = {0}; //!< VDEnc batch buffer slice size array 136 137 uint32_t m_picStateCmdStartInBytes = 0; //!< Offset of PIC_STATE cmd in batch buffer 138 139 HevcBasicFeature422 *m_422State= nullptr; 140 MOS_STATUS Init422State(); 141 142 std::deque<uint32_t> m_recycleBufferIdxes; 143 144 protected: 145 MOS_STATUS SetPictureStructs(); 146 virtual MOS_STATUS UpdateTrackedBufferParameters() override; 147 MOS_STATUS GetMaxMBPS(uint32_t levelIdc, uint32_t* maxMBPS, uint64_t* maxBytePerPic); 148 virtual MOS_STATUS GetTrackedBuffers() override; 149 MOS_STATUS SetSliceStructs(); 150 MOS_STATUS SetRoundingValues(); 151 //! 152 //! \brief Calculate maximum bitsize allowed for LCU 153 //! \details Calculate LCU max coding size according to log2_max_coding_block_size_minus3 154 //! 155 //! \return MOS_STATUS 156 //! MOS_STATUS_SUCCESS if success, else fail reason 157 //! 158 MOS_STATUS CalcLCUMaxCodingSize(); 159 virtual MOS_STATUS GetRecycleBuffers(); 160 161 void CreateDefaultScalingList(); 162 void CreateFlatScalingList(); 163 164 MEDIA_CLASS_DEFINE_END(encode__HevcBasicFeature) 165 }; 166 167 } // namespace encode 168 169 #endif // !__ENCODE_HEVC_BASIC_FEATURE_H__ 170