| 1 |
/* |
| 2 |
* Copyright (c) 2020, 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_av1_brc.h |
| 24 |
//! \brief Defines the common interface for av1 brc features |
| 25 |
//! |
| 26 |
#ifndef __ENCODE_AV1_BRC_H__ |
| 27 |
#define __ENCODE_AV1_BRC_H__ |
| 28 |
|
| 29 |
#include "media_feature.h" |
| 30 |
#include "encode_allocator.h" |
| 31 |
#include "encode_pipeline.h" |
| 32 |
#include "encode_recycle_resource.h" |
| 33 |
#include "encode_av1_basic_feature.h" |
| 34 |
|
| 35 |
namespace encode |
| 36 |
{ |
| 37 |
#define AV1_BRC_HUC_STATUS_REENCODE_MASK (1<<31) |
| 38 |
static const uint32_t BRC_KBPS = 1000; // 1000bps for disk storage, aligned with industry usage |
| 39 |
static const uint32_t BRC_DATA_SIZE = 16*4; |
| 40 |
|
| 41 |
enum AV1_BRC_FRAME_TYPE |
| 42 |
{ |
| 43 |
AV1_BRC_FRAME_TYPE_P_OR_LB = 0, |
| 44 |
AV1_BRC_FRAME_TYPE_B = 1, |
| 45 |
AV1_BRC_FRAME_TYPE_I = 2, |
| 46 |
AV1_BRC_FRAME_TYPE_B1 = 3, |
| 47 |
AV1_BRC_FRAME_TYPE_B2 = 4, |
| 48 |
AV1_BRC_FRAME_TYPE_B3 = 5, |
| 49 |
AV1_BRC_FRAME_TYPE_INVALID |
| 50 |
|
| 51 |
}; |
| 52 |
|
| 53 |
//! |
| 54 |
//! \struct Av1VdencPakInfo |
| 55 |
//! \brief AV1 Vdenc Pak info |
| 56 |
//! |
| 57 |
struct Av1VdencPakInfo |
| 58 |
{ |
| 59 |
uint32_t frameByteCount; |
| 60 |
uint8_t pakPassNum; |
| 61 |
}; |
| 62 |
struct SlbData |
| 63 |
{ |
| 64 |
//SLB related fields. |
| 65 |
uint16_t slbSize = 0; |
| 66 |
uint16_t avpPicStateCmdNum = 1; |
| 67 |
uint16_t avpSegmentStateOffset = 0; |
| 68 |
uint16_t avpInloopFilterStateOffset = 0; |
| 69 |
uint16_t vdencCmd1Offset = 0; |
| 70 |
uint16_t vdencCmd2Offset = 0; |
| 71 |
uint16_t avpPicStateOffset = 0; |
| 72 |
uint16_t secondAvpPicStateOffset = 0; |
| 73 |
uint16_t pakInsertSlbSize = 0; |
| 74 |
uint16_t vdencTileSliceStateOffset = 0; |
| 75 |
uint16_t tileNum = 1; |
| 76 |
}; |
| 77 |
//! |
| 78 |
//! \struct Av1BrcPakMmio |
| 79 |
//! \brief MMIO of BRC and PAK |
| 80 |
//! |
| 81 |
struct Av1BrcPakMmio |
| 82 |
{ |
| 83 |
uint32_t reEncode[4]; |
| 84 |
}; |
| 85 |
|
| 86 |
struct VdencAv1HucBrcInitDmem; |
| 87 |
struct VdencAv1HucBrcUpdateDmem; |
| 88 |
struct VdencAv1HucBrcConstantData; |
| 89 |
|
| 90 |
class Av1Brc : public MediaFeature, public mhw::vdbox::vdenc::Itf::ParSetting, public mhw::vdbox::huc::Itf::ParSetting |
| 91 |
{ |
| 92 |
public: |
| 93 |
Av1Brc(MediaFeatureManager *featureManager, EncodeAllocator *allocator, CodechalHwInterfaceNext *hwInterface, void *constSettings); |
| 94 |
|
| 95 |
virtual ~Av1Brc(); |
| 96 |
|
| 97 |
//! |
| 98 |
//! \brief Init av1 brc features related parameter |
| 99 |
//! \param [in] settings |
| 100 |
//! Pointer to settings |
| 101 |
//! \return MOS_STATUS |
| 102 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 103 |
//! |
| 104 |
MOS_STATUS Init(void *settings) override; |
| 105 |
|
| 106 |
//! |
| 107 |
//! \brief Update cqp basic features related parameter |
| 108 |
//! \param [in] params |
| 109 |
//! Pointer to parameters |
| 110 |
//! \return MOS_STATUS |
| 111 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 112 |
//! |
| 113 |
MOS_STATUS Update(void *params) override; |
| 114 |
|
| 115 |
//! |
| 116 |
//! \brief Check if BRC enabled |
| 117 |
//! |
| 118 |
//! \return bool |
| 119 |
//! true if BRC enabled, else BRC disabled. |
| 120 |
//! |
| 121 |
virtual bool IsBRCEnabled() const { return m_brcEnabled; } |
| 122 |
|
| 123 |
//! |
| 124 |
//! \brief Disable Brc Init and Reset after BRC update |
| 125 |
//! |
| 126 |
void DisableBrcInitReset() { m_brcInit = m_brcReset = false; }; |
| 127 |
|
| 128 |
//! |
| 129 |
//! \brief Check if BRC Init or Reset enabled |
| 130 |
//! |
| 131 |
//! \return bool |
| 132 |
//! true if BRC Init or Reset enabled. |
| 133 |
//! |
| 134 |
virtual bool IsBRCInitRequired() const { return m_brcEnabled & (m_brcInit || m_brcReset); } |
| 135 |
|
| 136 |
//! |
| 137 |
//! \brief Check if BRC Reset enabled |
| 138 |
//! |
| 139 |
//! \return bool |
| 140 |
//! true if BRC Reset enabled. |
| 141 |
//! |
| 142 |
virtual bool IsBRCResetRequired() const { return m_brcEnabled & m_brcReset; } |
| 143 |
|
| 144 |
PMHW_BATCH_BUFFER GetVdenc2ndLevelBatchBuffer(uint32_t currRecycledBufIdx) { |
| 145 |
return &m_vdenc2ndLevelBatchBuffer[currRecycledBufIdx]; |
| 146 |
}; |
| 147 |
|
| 148 |
PMHW_BATCH_BUFFER GetPakInsertOutputBatchBuffer(uint32_t currRecycledBufIdx) |
| 149 |
{ |
| 150 |
return &m_pakInsertOutputBatchBuffer[currRecycledBufIdx]; |
| 151 |
}; |
| 152 |
|
| 153 |
MOS_STATUS GetBrcDataBuffer(MOS_RESOURCE *&buffer); |
| 154 |
|
| 155 |
//! |
| 156 |
//! \brief Set Dmem buffer for brc update |
| 157 |
//! \param [in] params |
| 158 |
//! Pointer to parameters |
| 159 |
//! \return MOS_STATUS |
| 160 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 161 |
//! |
| 162 |
MOS_STATUS SetDmemForUpdate(VdencAv1HucBrcUpdateDmem *params) const; |
| 163 |
|
| 164 |
//! |
| 165 |
//! \brief Set Const data for brc update |
| 166 |
//! \param [in] params |
| 167 |
//! Pointer to parameters |
| 168 |
//! \return MOS_STATUS |
| 169 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 170 |
//! |
| 171 |
MOS_STATUS SetConstForUpdate(VdencAv1HucBrcConstantData *params) const; |
| 172 |
|
| 173 |
//! |
| 174 |
//! \brief Set Dmem buffer for brc Init |
| 175 |
//! \param [in] params |
| 176 |
//! Pointer to parameters |
| 177 |
//! \return MOS_STATUS |
| 178 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 179 |
//! |
| 180 |
MOS_STATUS SetDmemForInit(VdencAv1HucBrcInitDmem *params) const; |
| 181 |
|
| 182 |
const SlbData& GetSLBData() { return m_slbData; }; |
| 183 |
void SetSLBData(const SlbData& input) { m_slbData = input; }; |
| 184 |
|
| 185 |
protected: |
| 186 |
//! \brief Allocate feature related resources |
| 187 |
//! \return MOS_STATUS |
| 188 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 189 |
//! |
| 190 |
virtual MOS_STATUS AllocateResources() override; |
| 191 |
|
| 192 |
//! |
| 193 |
//! \brief Free resources |
| 194 |
//! \return MOS_STATUS |
| 195 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 196 |
//! |
| 197 |
virtual MOS_STATUS FreeBrcResources(); |
| 198 |
|
| 199 |
MOS_STATUS SetSequenceStructs(); |
| 200 |
|
| 201 |
MHW_SETPAR_DECL_HDR(VDENC_PIPE_MODE_SELECT); |
| 202 |
MHW_SETPAR_DECL_HDR(HUC_DMEM_STATE); |
| 203 |
MHW_SETPAR_DECL_HDR(HUC_VIRTUAL_ADDR_STATE); |
| 204 |
|
| 205 |
// const data |
| 206 |
static constexpr uint32_t m_brcHistoryBufSize = 6080; //!< BRC history buffer size |
| 207 |
|
| 208 |
CodechalHwInterfaceNext *m_hwInterface = nullptr; |
| 209 |
EncodeAllocator *m_allocator = nullptr; |
| 210 |
Av1BasicFeature *m_basicFeature = nullptr; //!< EncodeBasicFeature |
| 211 |
|
| 212 |
SlbData m_slbData = {}; |
| 213 |
uint8_t m_rcMode = 0; |
| 214 |
|
| 215 |
bool m_brcInit = true; //!< BRC init flag |
| 216 |
bool m_brcReset = false; //!< BRC reset flag |
| 217 |
bool m_brcEnabled = false; //!< BRC enable flag |
| 218 |
|
| 219 |
//Resources |
| 220 |
MHW_BATCH_BUFFER m_vdenc2ndLevelBatchBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; //!< VDEnc 2nd level batch buffer |
| 221 |
MHW_BATCH_BUFFER m_pakInsertOutputBatchBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; //!< PAK insert output batch buffer |
| 222 |
MOS_RESOURCE m_vdencBrcDbgBuffer = {}; //!< VDEnc brc debug buffer |
| 223 |
MOS_RESOURCE m_resBrcDataBuffer = {}; //!< Resource of bitrate control data buffer, only as an output of PAKintegrate Kernel |
| 224 |
|
| 225 |
MHW_VDBOX_NODE_IND m_vdboxIndex = MHW_VDBOX_NODE_1; |
| 226 |
|
| 227 |
mutable double m_curTargetFullness = 0; |
| 228 |
int32_t m_delay = 0; |
| 229 |
|
| 230 |
int32_t m_vbvSize = 0; |
| 231 |
int32_t m_frameRate = 0; |
| 232 |
double m_inputbitsperframe = 0; |
| 233 |
|
| 234 |
MEDIA_CLASS_DEFINE_END(encode__Av1Brc) |
| 235 |
}; |
| 236 |
|
| 237 |
} // namespace encode |
| 238 |
|
| 239 |
#endif // !__ENCODE_AV1_BRC_H__ |