1 /* 2 * Copyright (c) 2018, 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 //! 24 //! \file encode_hevc_vdenc_const_settings.h 25 //! \brief Defines the common interface for henvc vdenc const settings 26 //! \details The default setting is further sub-divided by platform type 27 //! this file is for the base interface which is shared by all components. 28 //! 29 30 #ifndef __ENCODE_HEVC_VDENC_CONST_SETTINGS_H__ 31 #define __ENCODE_HEVC_VDENC_CONST_SETTINGS_H__ 32 33 #include "codec_def_common_encode.h" 34 #include "codec_def_encode_hevc.h" 35 #include "encode_const_settings.h" 36 #include "media_class_trace.h" 37 #include "media_feature_const_settings.h" 38 #include "mos_defs.h" 39 #include <stdint.h> 40 #include <array> 41 #if _ENCODE_RESERVED 42 #include "encode_hevc_vdenc_const_settings_ext.h" 43 #endif // _ENCODE_RESERVED 44 45 #define HUC_MODE_COST_NUM 7 46 #define HUC_QP_RANGE 52 47 48 namespace encode 49 { 50 struct HevcVdencBrcSettings 51 { 52 ConstTableSet HevcVdencBrcSettings_0; 53 ConstTableSet HevcVdencBrcSettings_1; 54 ConstTableSet estRateThreshP0; 55 ConstTableSet estRateThreshB0; 56 ConstTableSet estRateThreshI0; 57 ConstTableSet instRateThreshP0; 58 ConstTableSet instRateThreshB0; 59 ConstTableSet instRateThreshI0; 60 61 ConstTableSet devThreshIFPNEG; 62 ConstTableSet devThreshIFPPOS; 63 ConstTableSet devThreshPBFPNEG; 64 ConstTableSet devThreshPBFPPOS; 65 ConstTableSet devThreshVBRNEG; 66 ConstTableSet devThreshVBRPOS; 67 ConstTableSet lowdelayDevThreshPB; 68 ConstTableSet lowdelayDevThreshVBR; 69 ConstTableSet lowdelayDevThreshI; 70 71 ConstTableSet startGAdjFrame; 72 73 uint32_t numDevThreshlds = 0; 74 double devStdFPS = 0; 75 double bpsRatioLow = 0; 76 double bpsRatioHigh = 0; 77 int32_t postMultPB = 0; 78 int32_t negMultPB = 0; 79 int32_t posMultVBR = 0; 80 int32_t negMultVBR = 0; 81 82 uint8_t topFrmSzThrForAdapt2Pass_U8 = 0; 83 uint8_t botFrmSzThrForAdapt2Pass_U8 = 0; 84 uint8_t topQPDeltaThrForAdapt2Pass_U8 = 0; 85 uint8_t botQPDeltaThrForAdapt2Pass_U8 = 0; 86 87 int8_t (*HevcVdencBrcSettings_4)[9][8] = nullptr; 88 int8_t (*HevcVdencBrcSettings_5)[9][8] = nullptr; 89 int8_t (*HevcVdencBrcSettings_6)[9][8] = nullptr; 90 91 ConstTableSet hucConstantData; 92 ConstTableSet HevcVdencBrcSettings_2; 93 ConstTableSet HevcVdencBrcSettings_3; 94 ConstTableSet HevcVdencBrcSettings_7; 95 ConstTableSet HevcVdencBrcSettings_8; 96 ConstTableSet rateRatioThreshold; 97 ConstTableSet startGAdjMult; 98 ConstTableSet startGAdjDiv; 99 ConstTableSet rateRatioThresholdQP; 100 101 int8_t deltaQPForSadZone0_S8 = 0; 102 int8_t deltaQPForSadZone1_S8 = 0; 103 int8_t deltaQPForSadZone2_S8 = 0; 104 int8_t deltaQPForSadZone3_S8 = 0; 105 int8_t deltaQPForMvZero_S8 = 0; 106 int8_t deltaQPForMvZone0_S8 = 0; 107 int8_t deltaQPForMvZone1_S8 = 0; 108 int8_t deltaQPForMvZone2_S8 = 0; 109 110 int8_t reEncodePositiveQPDeltaThr_S8 = 0; 111 int8_t reEncodeNegativeQPDeltaThr_S8 = 0; 112 uint8_t sceneChgPrevIntraPctThreshold_U8 = 0; 113 uint8_t sceneChgCurIntraPctThreshold_U8 = 0; 114 }; 115 116 struct HevcVdencArbSettings // adaptive region boot settings 117 { 118 const uint8_t m_roiCtrl = 85; // All four 16x16 blocks within the 32x32 blocks share the same region ID 1 (01010101) 119 const uint8_t m_maxCuSize = 2; // For ARB, currently supports 32x32 block 120 const std::array< 121 uint16_t, 122 8> 123 m_rowOffsetsForBoost = {{0, 3, 5, 2, 7, 4, 1, 6}}; 124 }; 125 126 struct HevcVdencFeatureSettings : VdencFeatureSettings 127 { 128 std::vector< 129 std::function< 130 MOS_STATUS(mhw::vdbox::vdenc::_MHW_PAR_T(VDENC_CMD1) & par, bool isLowDelay)> > 131 vdencLaCmd1Settings; 132 133 std::vector< 134 std::function< 135 MOS_STATUS(mhw::vdbox::vdenc::_MHW_PAR_T(VDENC_CMD2) & par, bool isLowDelay)> > 136 vdencLaCmd2Settings; 137 138 std::array<bool, NUM_TARGET_USAGE_MODES + 1> rdoqEnable{}; 139 std::array<bool, NUM_TARGET_USAGE_MODES + 1> acqpEnable{}; 140 std::array<bool, NUM_TARGET_USAGE_MODES + 1> rdoqLaEnable{}; 141 std::array<bool, NUM_TARGET_USAGE_MODES + 1> acqpLaEnable{}; 142 143 std::array< 144 std::array< 145 std::array< 146 std::array< 147 std::array<uint8_t, 148 2>, 149 2>, 150 2>, 151 2>, 152 4> 153 transformSkipCoeffsTable{}; 154 155 std::array<uint16_t, 52> transformSkipLambdaTable{}; 156 157 std::array< 158 std::array< 159 std::array< 160 std::array<uint16_t, 161 52>, 162 2>, 163 2>, 164 2> 165 rdoqLamdas8bits{}; 166 167 std::array< 168 std::array< 169 std::array< 170 std::array<uint16_t, 171 64>, 172 2>, 173 2>, 174 2> 175 rdoqLamdas10bits{}; 176 177 std::array< 178 std::array< 179 std::array< 180 std::array<uint16_t, 181 76>, 182 2>, 183 2>, 184 2> 185 rdoqLamdas12bits{}; 186 187 HevcVdencBrcSettings brcSettings = {}; 188 HevcVdencArbSettings arbSettings = {}; 189 }; 190 191 struct HevcVdencBrcConstSettings 192 { 193 static const uint16_t HevcVdencBrcConstSettings_0[52]; 194 static const uint16_t HevcVdencBrcConstSettings_1[52]; 195 static const uint8_t m_estRateThreshP0[7]; 196 static const uint8_t m_estRateThreshB0[7]; 197 static const uint8_t m_estRateThreshI0[7]; 198 static const int8_t m_instRateThreshP0[4]; 199 static const int8_t m_instRateThreshB0[4]; 200 static const int8_t m_instRateThreshI0[4]; 201 202 static constexpr uint32_t m_numDevThreshlds = 8; 203 static constexpr double m_devStdFPS = 30.0; 204 static constexpr double m_bpsRatioLow = 0.1; 205 static constexpr double m_bpsRatioHigh = 3.5; 206 static constexpr int32_t m_postMultPB = 50; 207 static constexpr int32_t m_negMultPB = -50; 208 static constexpr int32_t m_posMultVBR = 100; 209 static constexpr int32_t m_negMultVBR = -50; 210 211 static const double m_devThreshIFPNEG[m_numDevThreshlds / 2]; 212 static const double m_devThreshIFPPOS[m_numDevThreshlds / 2]; 213 static const double m_devThreshPBFPNEG[m_numDevThreshlds / 2]; 214 static const double m_devThreshPBFPPOS[m_numDevThreshlds / 2]; 215 static const double m_devThreshVBRNEG[m_numDevThreshlds / 2]; 216 static const double m_devThreshVBRPOS[m_numDevThreshlds / 2]; 217 static const int8_t m_lowdelayDevThreshPB[m_numDevThreshlds]; 218 static const int8_t m_lowdelayDevThreshVBR[m_numDevThreshlds]; 219 static const int8_t m_lowdelayDevThreshI[m_numDevThreshlds]; 220 221 static const uint16_t m_startGAdjFrame[4]; 222 223 static const uint32_t m_hucConstantData[]; 224 static const uint16_t HevcVdencBrcConstSettings_2[52]; 225 static const uint16_t HevcVdencBrcConstSettings_3[52]; 226 static const uint32_t HevcVdencBrcConstSettings_7[364]; 227 static const uint32_t HevcVdencBrcConstSettings_8[364]; 228 static const int8_t HevcVdencBrcConstSettings_4[9][8]; 229 static const int8_t HevcVdencBrcConstSettings_5[9][8]; 230 static const int8_t HevcVdencBrcConstSettings_6[9][8]; 231 static const uint8_t m_rateRatioThreshold[7]; 232 static const uint8_t m_startGAdjMult[5]; 233 static const uint8_t m_startGAdjDiv[5]; 234 static const uint8_t m_rateRatioThresholdQP[8]; 235 236 static constexpr uint8_t m_topFrmSzThrForAdapt2Pass_U8 = 32; 237 static constexpr uint8_t m_botFrmSzThrForAdapt2Pass_U8 = 24; 238 static constexpr uint8_t m_topQPDeltaThrForAdapt2Pass_U8 = 2; 239 static constexpr uint8_t m_botQPDeltaThrForAdapt2Pass_U8 = 1; 240 241 static const int8_t m_deltaQPForSadZone0_S8 = -1; 242 static const int8_t m_deltaQPForSadZone1_S8 = 0; 243 static const int8_t m_deltaQPForSadZone2_S8 = 1; 244 static const int8_t m_deltaQPForSadZone3_S8 = 2; 245 static const int8_t m_deltaQPForMvZero_S8 = 3; 246 static const int8_t m_deltaQPForMvZone0_S8 = -2; 247 static const int8_t m_deltaQPForMvZone1_S8 = 0; 248 static const int8_t m_deltaQPForMvZone2_S8 = 2; 249 250 static const int8_t m_reEncodePositiveQPDeltaThr_S8 = 4; 251 static const int8_t m_reEncodeNegativeQPDeltaThr_S8 = -5; 252 static const uint8_t m_sceneChgPrevIntraPctThreshold_U8 = 96; 253 static const uint8_t m_sceneChgCurIntraPctThreshold_U8 = 192; 254 }; 255 256 class EncodeHevcVdencConstSettings : public VdencConstSettings 257 { 258 public: 259 260 //! 261 //! \brief EncodeHevcVdencConstSettings constructor 262 //! 263 EncodeHevcVdencConstSettings(); 264 265 //! 266 //! \brief EncodeHevcVdencConstSettings destructor 267 //! 268 ~EncodeHevcVdencConstSettings(); 269 270 MOS_STATUS PrepareConstSettings() override; 271 272 MOS_STATUS Update(void *params) override; 273 274 protected: 275 MOS_STATUS SetTUSettings() override; 276 277 MOS_STATUS SetCommonSettings() override; 278 279 MOS_STATUS SetVdencStreaminStateSettings() override; 280 281 MOS_STATUS SetVdencCmd1Settings() override; 282 SetVdencCmd2Settings()283 MOS_STATUS SetVdencCmd2Settings() override 284 { 285 return MOS_STATUS_SUCCESS; 286 } 287 288 MOS_STATUS SetLaTUSettings(); 289 MOS_STATUS SetVdencLaCmd1Settings(); 290 MOS_STATUS SetVdencLaCmd2Settings(); 291 292 MOS_STATUS SetBrcSettings() override; 293 294 HevcVdencBrcConstSettings m_brcSettings; 295 296 PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS m_hevcSeqParams = nullptr; 297 PCODEC_HEVC_ENCODE_PICTURE_PARAMS m_hevcPicParams = nullptr; 298 PCODEC_HEVC_ENCODE_SLICE_PARAMS m_hevcSliceParams = nullptr; 299 300 bool m_hevcVdencRoundingPrecisionEnabled = true; //!< Roinding Precision enabled 301 bool m_hevcRdoqEnabled = false; 302 bool m_isLaSetting = false; 303 304 MEDIA_CLASS_DEFINE_END(encode__EncodeHevcVdencConstSettings) 305 }; 306 307 } 308 #endif // !__ENCODE_HEVC_VDENC_CONST_SETTINGS_H__ 309