1 /* 2 * Copyright (c) 2019, 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_av1_vdenc_const_settings.h 25 //! \brief Defines the common interface for av1 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_AV1_VDENC_CONST_SETTINGS_H__ 31 #define __ENCODE_AV1_VDENC_CONST_SETTINGS_H__ 32 33 #include "codec_def_common_encode.h" 34 #include "codec_def_encode_av1.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 "mos_os.h" 40 #include "mos_os_specific.h" 41 #include <stdint.h> 42 #if _ENCODE_RESERVED 43 #include "mhw_vdbox_vdenc_cmdpar_ext.h" 44 #endif // _ENCODE_RESERVED 45 46 namespace encode 47 { 48 struct Av1VdencBrcSettings 49 { 50 int32_t numInstRateThresholds; 51 ConstTableSet instRateThresholdP; 52 ConstTableSet instRateThresholdI; 53 54 double devStdFPS; 55 double bpsRatioLow; 56 double bpsRatioHigh; 57 int32_t postMultPB; 58 int32_t negMultPB; 59 int32_t posMultVBR; 60 int32_t negMultVBR; 61 62 uint32_t numDevThreshlds; 63 ConstTableSet devThresholdFpNegI; 64 ConstTableSet devThresholdFpPosI; 65 ConstTableSet devThresholdFpNegPB; 66 ConstTableSet devThresholdFpPosPB; 67 ConstTableSet devThresholdVbrNeg; 68 ConstTableSet devThresholdVbrPos; 69 70 uint32_t numQpThresholds; 71 ConstTableSet QPThresholds; 72 uint32_t numGlobalRateRatioThreshlds; 73 ConstTableSet startGlobalAdjustFrame; 74 ConstTableSet globalRateRatioThreshold; 75 ConstTableSet globalRateRatioThresholdQP; 76 uint32_t numStartGlobalAdjusts; 77 ConstTableSet startGlobalAdjustMult; 78 ConstTableSet startGlobalAdjustDiv; 79 uint32_t numDistortionThresholds; 80 ConstTableSet distortionThresh; 81 ConstTableSet distortionThreshB; 82 ConstTableSet maxFrameMultI; 83 ConstTableSet maxFrameMultP; 84 ConstTableSet av1DeltaQpI; 85 ConstTableSet av1DeltaQpP; 86 ConstTableSet av1DistortionsDeltaQpI; 87 ConstTableSet av1DistortionsDeltaQpP; 88 ConstTableSet loopFilterLevelTabLuma; 89 ConstTableSet loopFilterLevelTabChroma; 90 ConstTableSet hucModeCostsIFrame; 91 ConstTableSet hucModeCostsPFrame; 92 }; 93 94 struct Av1VdencFeatureSettings : VdencFeatureSettings 95 { 96 Av1VdencBrcSettings brcSettings = {}; 97 double av1Table[239] = {}; 98 }; 99 100 struct Av1VdencTUConstSettings 101 { 102 static const uint8_t vdencCmd2Par39[NUM_TARGET_USAGE_MODES]; 103 static const uint8_t vdencCmd2Par38[NUM_TARGET_USAGE_MODES]; 104 static const uint32_t vdencCmd2Par85Table0[NUM_TARGET_USAGE_MODES]; 105 static const uint32_t vdencCmd2Par85Table1[NUM_TARGET_USAGE_MODES]; 106 static const bool vdencCmd2Par86[NUM_TARGET_USAGE_MODES]; 107 static const uint8_t vdencCmd2Par87Table0[NUM_TARGET_USAGE_MODES]; 108 static const uint8_t vdencCmd2Par87Table1[NUM_TARGET_USAGE_MODES]; 109 static const uint8_t vdencCmd2Par87Table2[NUM_TARGET_USAGE_MODES]; 110 static const uint8_t vdencCmd2Par87Table3[NUM_TARGET_USAGE_MODES]; 111 static const uint8_t vdencCmd2Par88Table0[NUM_TARGET_USAGE_MODES]; 112 static const uint8_t vdencCmd2Par88Table1[NUM_TARGET_USAGE_MODES]; 113 static const uint8_t vdencCmd2Par88Table2[NUM_TARGET_USAGE_MODES]; 114 static const uint8_t vdencCmd2Par88Table3[NUM_TARGET_USAGE_MODES]; 115 static const uint8_t vdencCmd2Par88Table4[NUM_TARGET_USAGE_MODES]; 116 static const uint8_t vdencCmd2Par88Table5[NUM_TARGET_USAGE_MODES]; 117 static const uint8_t vdencCmd2Par88Table6[NUM_TARGET_USAGE_MODES]; 118 static const uint8_t vdencCmd2Par88Table7[NUM_TARGET_USAGE_MODES]; 119 static const uint8_t vdencCmd2Par88Table8[NUM_TARGET_USAGE_MODES]; 120 static const uint8_t vdencCmd2Par88Table9[NUM_TARGET_USAGE_MODES]; 121 static const uint8_t vdencCmd2Par88Table10[NUM_TARGET_USAGE_MODES]; 122 static const uint8_t vdencCmd2Par88Table11[NUM_TARGET_USAGE_MODES]; 123 static const bool vdencCmd2Par89[NUM_TARGET_USAGE_MODES]; 124 static const bool vdencCmd2Par94[NUM_TARGET_USAGE_MODES]; 125 static const bool vdencCmd2Par95[NUM_TARGET_USAGE_MODES]; 126 static const uint8_t vdencCmd2Par98[NUM_TARGET_USAGE_MODES]; 127 static const bool vdencCmd2Par97[NUM_TARGET_USAGE_MODES]; 128 static const uint8_t vdencCmd2Par100[NUM_TARGET_USAGE_MODES]; 129 static const uint8_t vdencCmd2Par96[NUM_TARGET_USAGE_MODES]; 130 static const uint16_t vdencCmd2Par93[NUM_TARGET_USAGE_MODES]; 131 static const uint16_t vdencCmd2Par92[NUM_TARGET_USAGE_MODES]; 132 static const bool vdencCmd2Par23[NUM_TARGET_USAGE_MODES]; 133 }; 134 135 struct Av1VdencBrcConstSettings 136 { 137 //BRC INIT related const data 138 static const int32_t numInstRateThresholds = 4; 139 static const int8_t instRateThresholdP[numInstRateThresholds]; 140 static const int8_t instRateThresholdI[numInstRateThresholds]; 141 142 static constexpr double devStdFPS = 30.0; 143 static constexpr double bpsRatioLow = 0.1f; 144 static constexpr double bpsRatioHigh = 3.5; 145 static constexpr int32_t postMultPB = 50; 146 static constexpr int32_t negMultPB = -50; 147 static constexpr int32_t posMultVBR = 100; 148 static constexpr int32_t negMultVBR = -50; 149 150 static constexpr uint32_t numDevThreshlds = 8; 151 static const double devThresholdFpNegI[numDevThreshlds / 2]; 152 static const double devThresholdFpPosI[numDevThreshlds / 2]; 153 static const double devThresholdFpNegPB[numDevThreshlds / 2]; 154 static const double devThresholdFpPosPB[numDevThreshlds / 2]; 155 static const double devThresholdVbrNeg[numDevThreshlds / 2]; 156 static const double devThresholdVbrPos[numDevThreshlds / 2]; 157 158 // BRC UPDATE related const data 159 static constexpr uint32_t numQpThresholds = 4; 160 static const uint8_t QPThresholds[numQpThresholds]; 161 static constexpr uint32_t numGlobalRateRatioThreshlds = 6; 162 static const uint16_t startGlobalAdjustFrame[4]; 163 static const uint8_t globalRateRatioThreshold[numGlobalRateRatioThreshlds]; 164 static const int8_t globalRateRatioThresholdQP[numGlobalRateRatioThreshlds + 1]; 165 static constexpr uint32_t numStartGlobalAdjusts = 4; 166 static const uint8_t startGlobalAdjustMult[numStartGlobalAdjusts + 1]; 167 static const uint8_t startGlobalAdjustDiv[numStartGlobalAdjusts + 1]; 168 static constexpr uint32_t numDistortionThresholds = 8; 169 static const uint8_t distortionThresh[numDistortionThresholds + 1]; 170 static const uint8_t distortionThreshB[numDistortionThresholds + 1]; 171 static const uint8_t maxFrameMultI[numQpThresholds + 1]; 172 static const uint8_t maxFrameMultP[numQpThresholds + 1]; 173 static const int8_t av1DeltaQpI[][numQpThresholds + 1]; 174 static const int8_t av1DeltaQpP[][numQpThresholds + 1]; 175 static const int8_t av1DistortionsDeltaQpI[][numDistortionThresholds + 1]; 176 static const int8_t av1DistortionsDeltaQpP[][numDistortionThresholds + 1]; 177 static const uint8_t loopFilterLevelTabLuma[256]; 178 static const uint8_t loopFilterLevelTabChroma[256]; 179 static const uint32_t hucModeCostsIFrame[52*6]; 180 static const uint32_t hucModeCostsPFrame[52*6]; 181 }; 182 183 class EncodeAv1VdencConstSettings : public VdencConstSettings 184 { 185 public: 186 187 //! 188 //! \brief EncodeAv1VdencConstSettings constructor 189 //! 190 EncodeAv1VdencConstSettings(PMOS_INTERFACE osInterface); 191 192 //! 193 //! \brief EncodeAv1VdencConstSettings deconstructor 194 //! ~EncodeAv1VdencConstSettings()195 virtual ~EncodeAv1VdencConstSettings() {} 196 197 //! 198 //! \brief Prepare const settings 199 //! \return MOS_STATUS 200 //! MOS_STATUS_SUCCESS if success, else fail reason 201 //! 202 virtual MOS_STATUS PrepareConstSettings() override; 203 204 MOS_STATUS Update(void* params) override; 205 206 virtual MOS_STATUS SetVdencCmd1Settings() override; 207 SetVdencCmd2Settings()208 virtual MOS_STATUS SetVdencCmd2Settings() override { return MOS_STATUS_SUCCESS; } 209 210 protected: 211 212 //! 213 //! \brief Prepare BRC related settings 214 //! \return MOS_STATUS 215 //! MOS_STATUS_SUCCESS if success, else fail reason 216 //! 217 virtual MOS_STATUS SetBrcSettings() override; 218 219 //! 220 //! \brief Prepare table related settings 221 //! \return MOS_STATUS 222 //! MOS_STATUS_SUCCESS if success, else fail reason 223 //! SetTable()224 virtual MOS_STATUS SetTable() {return MOS_STATUS_SUCCESS;}; 225 226 //! 227 //! \brief Prepare common settings 228 //! \return MOS_STATUS 229 //! MOS_STATUS_SUCCESS if success, else fail reason 230 //! 231 virtual MOS_STATUS SetCommonSettings() override; 232 233 protected: 234 PMOS_INTERFACE m_osInterface = nullptr; 235 PCODEC_AV1_ENCODE_SEQUENCE_PARAMS m_av1SeqParams = nullptr; 236 PCODEC_AV1_ENCODE_PICTURE_PARAMS m_av1PicParams = nullptr; 237 238 MEDIA_CLASS_DEFINE_END(encode__EncodeAv1VdencConstSettings) 239 }; 240 241 242 } 243 #endif // !__ENCODE_AV1_VDENC_CONST_SETTINGS_H__ 244