| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#ifndef __ENCODE_AVC_BRC_H__ |
| 27 |
#define __ENCODE_AVC_BRC_H__ |
| 28 |
|
| 29 |
#include "media_feature.h" |
| 30 |
#include "encode_allocator.h" |
| 31 |
#include "codec_hw_next.h" |
| 32 |
#include "encode_avc_basic_feature.h" |
| 33 |
#include "mhw_vdbox_vdenc_itf.h" |
| 34 |
#include "mhw_vdbox_mfx_itf.h" |
| 35 |
#include "mhw_mi_itf.h" |
| 36 |
|
| 37 |
#if (_SW_BRC) |
| 38 |
#include "encode_sw_brc.h" |
| 39 |
#endif |
| 40 |
|
| 41 |
namespace encode |
| 42 |
{ |
| 43 |
struct VdencAvcHucBrcUpdateDmem; |
| 44 |
|
| 45 |
class AvcEncodeBRC : public MediaFeature, |
| 46 |
public mhw::vdbox::vdenc::Itf::ParSetting, |
| 47 |
public mhw::vdbox::huc::Itf::ParSetting |
| 48 |
{ |
| 49 |
enum AvcBrcFrameType |
| 50 |
{ |
| 51 |
P_FRAME = 0, |
| 52 |
B_FRAME = 1, |
| 53 |
I_FRAME = 2, |
| 54 |
B1_FRAME = 3, |
| 55 |
B2_FRAME = 4, |
| 56 |
}; |
| 57 |
|
| 58 |
public: |
| 59 |
AvcEncodeBRC(MediaFeatureManager *featureManager, |
| 60 |
EncodeAllocator *allocator, |
| 61 |
CodechalHwInterfaceNext *hwInterface, |
| 62 |
void *constSettings); |
| 63 |
|
| 64 |
virtual ~AvcEncodeBRC(); |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
MOS_STATUS Init(void *settings) override; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
MOS_STATUS Update(void *params) override; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
void DisableBrcInitReset() { m_brcInit = m_brcReset = false; } |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
void EnableVdencSinglePass() { m_vdencSinglePassEnable = true; } |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
bool IsBRCInit() { return m_brcInit; } |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
virtual bool IsBRCInitRequired() { return m_vdencBrcEnabled & (m_brcInit || m_brcReset); } |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
virtual bool IsBRCUpdateRequired() { return m_vdencBrcEnabled; } |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
virtual bool IsVdencBrcEnabled() { return m_vdencBrcEnabled; } |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
bool IsVdencBrcSupported(PCODEC_AVC_ENCODE_SEQUENCE_PARAMS avcSeqParams); |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
virtual bool IsMbBrcEnabled() { return m_mbBrcEnabled; } |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
bool IsRateControlBrc(uint8_t rc) |
| 153 |
{ |
| 154 |
return (rc == RATECONTROL_CBR) || |
| 155 |
(rc == RATECONTROL_VBR) || |
| 156 |
(rc == RATECONTROL_AVBR) || |
| 157 |
(rc == RATECONTROL_CQL) || |
| 158 |
(rc == RATECONTROL_VCM) || |
| 159 |
(rc == RATECONTROL_ICQ) || |
| 160 |
(rc == RATECONTROL_QVBR) || |
| 161 |
(rc == RATECONTROL_IWD_VBR); |
| 162 |
} |
| 163 |
|
| 164 |
PMHW_BATCH_BUFFER GetBatchBufferForVdencImgStat() { return &m_batchBufferForVdencImgStat; } |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
virtual MOS_STATUS SetDmemForInit(void *params); |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
MOS_STATUS SetDmemForUpdate(void *params, uint16_t currPass, bool bIsLastPass); |
| 185 |
|
| 186 |
virtual MOS_STATUS FillHucConstData(uint8_t *data, uint8_t pictureType); |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
MOS_STATUS SetMfcStatusParams(EncodeStatusReadParams ¶ms); |
| 198 |
|
| 199 |
virtual MOS_STATUS SaveBrcUpdateDmemBufferPtr( |
| 200 |
PMOS_RESOURCE vdencBrcUpdateDmemBuffer0, |
| 201 |
PMOS_RESOURCE vdencBrcUpdateDmemBuffer1); |
| 202 |
|
| 203 |
virtual MOS_STATUS SaveHucStatus2Buffer(PMOS_RESOURCE hucStatus2Buffer); |
| 204 |
|
| 205 |
virtual PMOS_RESOURCE GetHucStatus2Buffer() { return m_hucStatus2BufferPtr; } |
| 206 |
|
| 207 |
uint16_t GetAdaptiveRoundingNumSlices() const { return static_cast<uint16_t>(m_basicFeature->m_numSlices); } |
| 208 |
|
| 209 |
uint32_t GetVdencBRCImgStateBufferSize(); |
| 210 |
|
| 211 |
uint32_t GetVdencOneSliceStateSize(); |
| 212 |
|
| 213 |
bool IsBPyramidWithGoldenBGOP(); |
| 214 |
|
| 215 |
MHW_SETPAR_DECL_HDR(VDENC_PIPE_MODE_SELECT); |
| 216 |
MHW_SETPAR_DECL_HDR(HUC_VIRTUAL_ADDR_STATE); |
| 217 |
|
| 218 |
#if _SW_BRC |
| 219 |
std::shared_ptr<EncodeSwBrc> m_swBrc = nullptr; |
| 220 |
#endif |
| 221 |
|
| 222 |
protected: |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
virtual MOS_STATUS AllocateResources() override; |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
virtual MOS_STATUS FreeBrcResources(); |
| 235 |
|
| 236 |
MOS_STATUS SetSequenceStructs(); |
| 237 |
|
| 238 |
void SetMbBrc(); |
| 239 |
|
| 240 |
virtual MOS_STATUS LoadConstTable0(uint8_t constTable[8][42]); |
| 241 |
virtual MOS_STATUS LoadConstTable3(uint8_t pictureType, uint8_t ConstTable3[42]); |
| 242 |
virtual MOS_STATUS LoadConstTable5(uint8_t pictureType, uint16_t ConstTable5[42]); |
| 243 |
virtual MOS_STATUS LoadConstTable6(uint8_t pictureType, uint16_t ConstTable6[42]); |
| 244 |
virtual MOS_STATUS LoadConstTable7(uint8_t pictureType, uint8_t ConstTable7[42]); |
| 245 |
virtual MOS_STATUS LoadConstTable8(uint8_t pictureType, uint8_t ConstTable8[42]); |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
int32_t ComputeBRCInitQP(uint16_t framesFieldsPer100Sec); |
| 252 |
|
| 253 |
MOS_STATUS DeltaQPUpdate(uint8_t qpModulationStrength, bool bIsLastPass); |
| 254 |
|
| 255 |
void SetFrameTypeForUpdate(VdencAvcHucBrcUpdateDmem *dmem, uint16_t currPass); |
| 256 |
|
| 257 |
void CalculateCurLvlInBGop(uint16_t curFrameIdxInBGop, uint16_t begin, uint16_t end, uint16_t curLvl, uint16_t &curOrder, uint16_t &retLvl); |
| 258 |
|
| 259 |
CodechalHwInterfaceNext *m_hwInterface = nullptr; |
| 260 |
EncodeAllocator *m_allocator = nullptr; |
| 261 |
AvcBasicFeature *m_basicFeature = nullptr; |
| 262 |
|
| 263 |
std::shared_ptr<mhw::vdbox::vdenc::Itf> m_vdencItf = nullptr; |
| 264 |
std::shared_ptr<mhw::vdbox::mfx::Itf> m_mfxItf = nullptr; |
| 265 |
std::shared_ptr<mhw::mi::Itf> m_miItf = nullptr; |
| 266 |
|
| 267 |
|
| 268 |
MHW_BATCH_BUFFER m_batchBufferForVdencImgStat = {}; |
| 269 |
|
| 270 |
|
| 271 |
PMOS_RESOURCE m_vdencBrcUpdateDmemBufferPtr[2] = {nullptr, nullptr}; |
| 272 |
PMOS_RESOURCE m_hucStatus2BufferPtr = nullptr; |
| 273 |
|
| 274 |
uint8_t m_rcMode = 0; |
| 275 |
|
| 276 |
bool m_brcInit = true; |
| 277 |
bool m_brcReset = false; |
| 278 |
bool m_mbBrcEnabled = false; |
| 279 |
bool m_mbBrcUserFeatureKeyControl = false; |
| 280 |
bool m_vdencBrcEnabled = false; |
| 281 |
bool m_vdencSinglePassEnable = false; |
| 282 |
bool m_isFirstDeltaQPCalculation = true; |
| 283 |
|
| 284 |
double m_dBrcInitCurrentTargetBufFullInBits = 0; |
| 285 |
double m_dBrcInitResetInputBitsPerFrame = 0; |
| 286 |
uint32_t m_brcInitPreviousTargetBufFullInBits = 0; |
| 287 |
double m_dBrcTargetSize = 0; |
| 288 |
uint8_t m_qpModulationStrength = 0; |
| 289 |
|
| 290 |
uint16_t m_frameIdxInBGop = 0; |
| 291 |
|
| 292 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 293 |
static const uint32_t m_bufferFulnessDataSize = 600; |
| 294 |
uint32_t m_bufferFulnessData_csv[m_bufferFulnessDataSize] = {}; |
| 295 |
bool m_useBufferFulnessData = false; |
| 296 |
#endif |
| 297 |
|
| 298 |
MEDIA_CLASS_DEFINE_END(encode__AvcEncodeBRC) |
| 299 |
}; |
| 300 |
|
| 301 |
} |
| 302 |
|
| 303 |
#endif |