| 1 |
/* |
| 2 |
* Copyright (c) 2017, 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 codechal_encode_mpeg2.h |
| 24 |
//! \brief Defines base class for MPEG2 dual-pipe encoder. |
| 25 |
//! |
| 26 |
|
| 27 |
#ifndef __CODECHAL_ENCODE_MPEG2_H__ |
| 28 |
#define __CODECHAL_ENCODE_MPEG2_H__ |
| 29 |
|
| 30 |
#include "codechal_encoder_base.h" |
| 31 |
|
| 32 |
class CodechalKernelHme; |
| 33 |
|
| 34 |
//! |
| 35 |
//! \class CodechalEncodeMpeg2 |
| 36 |
//! \brief MPEG2 dual-pipe encoder base class |
| 37 |
//! \details This class defines the base class for MPEG2 dual-pipe encoder, it includes |
| 38 |
//! common member fields, functions, interfaces etc shared by all GENs. |
| 39 |
//! Gen specific definitions, features should be put into their corresponding classes. |
| 40 |
//! To create a MPEG2 dual-pipe encoder instance, client needs to new the instance in media interfaces |
| 41 |
//! |
| 42 |
class CodechalEncodeMpeg2 : public CodechalEncoderState |
| 43 |
{ |
| 44 |
public: |
| 45 |
|
| 46 |
//! |
| 47 |
//! \brief Copy construtor |
| 48 |
//! |
| 49 |
CodechalEncodeMpeg2(const CodechalEncodeMpeg2&) = delete; |
| 50 |
|
| 51 |
|
| 52 |
//! |
| 53 |
//! \brief Copy assignment construtor |
| 54 |
//! |
| 55 |
CodechalEncodeMpeg2& operator=(const CodechalEncodeMpeg2&) = delete; |
| 56 |
|
| 57 |
//! |
| 58 |
//! \brief Destructor |
| 59 |
//! |
| 60 |
virtual ~CodechalEncodeMpeg2(); |
| 61 |
|
| 62 |
//! |
| 63 |
//! \brief Allocate resources for encoder instance |
| 64 |
//! \details It is invoked when initializing encoder instance and it would call #AllocateEncResources(), #AllocateBrcResources() |
| 65 |
//! |
| 66 |
//! \return MOS_STATUS |
| 67 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 68 |
//! |
| 69 |
MOS_STATUS AllocateResources() override; |
| 70 |
|
| 71 |
//! |
| 72 |
//! \brief Free encoder resources |
| 73 |
//! \details It is invoked when destorying encoder instance and it would call #FreeEncResources(), #FreeBrcResources() |
| 74 |
//! and FreePakResources() |
| 75 |
//! |
| 76 |
//! \return void |
| 77 |
//! |
| 78 |
void FreeResources() override; |
| 79 |
|
| 80 |
//! |
| 81 |
//! \brief Initialize encoder at picture level |
| 82 |
//! |
| 83 |
//! \param [in] params |
| 84 |
//! Picture encoding parameters |
| 85 |
//! |
| 86 |
//! \return MOS_STATUS |
| 87 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 88 |
//! |
| 89 |
MOS_STATUS InitializePicture(const EncoderParams& params) override; |
| 90 |
|
| 91 |
//! |
| 92 |
//! \brief Encode kernel functions |
| 93 |
//! |
| 94 |
//! \return MOS_STATUS |
| 95 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 96 |
//! |
| 97 |
virtual MOS_STATUS ExecuteKernelFunctions() override; |
| 98 |
|
| 99 |
//! |
| 100 |
//! \brief Encode command at picture level |
| 101 |
//! |
| 102 |
//! \return MOS_STATUS |
| 103 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 104 |
//! |
| 105 |
MOS_STATUS ExecutePictureLevel() override; |
| 106 |
|
| 107 |
//! |
| 108 |
//! \brief Encode command at slice level |
| 109 |
//! |
| 110 |
//! \return MOS_STATUS |
| 111 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 112 |
//! |
| 113 |
MOS_STATUS ExecuteSliceLevel() override; |
| 114 |
|
| 115 |
//! |
| 116 |
//! \brief Copy skip frame |
| 117 |
//! |
| 118 |
//! \return MOS_STATUS |
| 119 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 120 |
//! |
| 121 |
MOS_STATUS EncodeCopySkipFrame() override; |
| 122 |
|
| 123 |
//! |
| 124 |
//! \brief Initialize encoder instance |
| 125 |
//! \details When GEN specific derived class implements this function to do its own initialization, |
| 126 |
// it is required that the derived class calls #CodechalEncodeMpeg2::Initialize() first |
| 127 |
// which would do common initialization for all GENs |
| 128 |
//! |
| 129 |
//! \return MOS_STATUS |
| 130 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 131 |
//! |
| 132 |
virtual MOS_STATUS Initialize(CodechalSetting * codecHalSettings) override; |
| 133 |
|
| 134 |
//! |
| 135 |
//! \brief Inserts the generic prologue command for a command buffer |
| 136 |
//! \param [in] cmdBuffer |
| 137 |
//! Command buffer |
| 138 |
//! \param [in] frameTracking |
| 139 |
//! Indicate if frame tracking requested |
| 140 |
//! \return MOS_STATUS |
| 141 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 142 |
//! |
| 143 |
virtual MOS_STATUS SendPrologWithFrameTracking( |
| 144 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 145 |
bool frameTracking, |
| 146 |
MHW_MI_MMIOREGISTERS *mmioRegister = nullptr) override; |
| 147 |
|
| 148 |
//! |
| 149 |
//! \brief Initialize MMC state |
| 150 |
//! |
| 151 |
//! \return MOS_STATUS |
| 152 |
//! MOS_STATUS_SUCCESS if success |
| 153 |
//! |
| 154 |
virtual MOS_STATUS InitMmcState(); |
| 155 |
|
| 156 |
CodecEncodeMpeg2PictureParams *m_picParams = nullptr; //!< Pointer to picture parameter |
| 157 |
PCODEC_REF_LIST m_refList[CODECHAL_NUM_UNCOMPRESSED_SURFACE_MPEG2]; //!< Pointer to reference list |
| 158 |
|
| 159 |
// Codec to define its own GetStatusReport |
| 160 |
MOS_STATUS GetStatusReport( |
| 161 |
EncodeStatus *encodeStatus, |
| 162 |
EncodeStatusReport *encodeStatusReport) override { return MOS_STATUS_SUCCESS; } |
| 163 |
|
| 164 |
MOS_STATUS AddMediaVfeCmd( |
| 165 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 166 |
SendKernelCmdsParams *params) override; |
| 167 |
|
| 168 |
protected: |
| 169 |
|
| 170 |
//! |
| 171 |
//! \brief Constructor |
| 172 |
//! |
| 173 |
CodechalEncodeMpeg2( |
| 174 |
CodechalHwInterface* hwInterface, |
| 175 |
CodechalDebugInterface* debugInterface, |
| 176 |
PCODECHAL_STANDARD_INFO standardInfo); |
| 177 |
|
| 178 |
//! |
| 179 |
//! \brief Help function to allocate a 1D buffer |
| 180 |
//! |
| 181 |
//! \param [in,out] buffer |
| 182 |
//! Pointer to allocated buffer |
| 183 |
//! \param [in] bufSize |
| 184 |
//! Buffer size |
| 185 |
//! \param [in] name |
| 186 |
//! Buffer name |
| 187 |
//! |
| 188 |
//! \return MOS_STATUS |
| 189 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 190 |
//! |
| 191 |
MOS_STATUS AllocateBuffer( |
| 192 |
PMOS_RESOURCE buffer, |
| 193 |
uint32_t bufSize, |
| 194 |
PCCHAR name); |
| 195 |
|
| 196 |
//! |
| 197 |
//! \brief Help function to allocate a generic 2D surface |
| 198 |
//! |
| 199 |
//! \param [in,out] surface |
| 200 |
//! Pointer to allocated surface |
| 201 |
//! \param [in] surfWidth |
| 202 |
//! Surface width |
| 203 |
//! \param [in] surfHeight |
| 204 |
//! Surface height |
| 205 |
//! \param [in] name |
| 206 |
//! Surface name |
| 207 |
//! |
| 208 |
//! \return MOS_STATUS |
| 209 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 210 |
//! |
| 211 |
MOS_STATUS AllocateBuffer2D( |
| 212 |
PMOS_SURFACE surface, |
| 213 |
uint32_t surfWidth, |
| 214 |
uint32_t surfHeight, |
| 215 |
PCCHAR name); |
| 216 |
|
| 217 |
//! |
| 218 |
//! \brief Help function to allocate a 1D buffer |
| 219 |
//! |
| 220 |
//! \param [in,out] batchBuffer |
| 221 |
//! Pointer to allocated batch buffer |
| 222 |
//! \param [in] bufSize |
| 223 |
//! Buffer size |
| 224 |
//! \param [in] name |
| 225 |
//! Batch buffer name |
| 226 |
//! |
| 227 |
//! \return MOS_STATUS |
| 228 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 229 |
//! |
| 230 |
MOS_STATUS AllocateBatchBuffer( |
| 231 |
PMHW_BATCH_BUFFER batchBuffer, |
| 232 |
uint32_t bufSize, |
| 233 |
PCCHAR name); |
| 234 |
|
| 235 |
//! |
| 236 |
//! \brief Allocate resources for ENC |
| 237 |
//! |
| 238 |
//! \return MOS_STATUS |
| 239 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 240 |
//! |
| 241 |
MOS_STATUS AllocateEncResources(); |
| 242 |
|
| 243 |
//! |
| 244 |
//! \brief Allocate BRC resources |
| 245 |
//! |
| 246 |
//! \return MOS_STATUS |
| 247 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 248 |
//! |
| 249 |
MOS_STATUS AllocateBrcResources(); |
| 250 |
|
| 251 |
//! |
| 252 |
//! \brief Free BRC resources |
| 253 |
//! |
| 254 |
//! \return MOS_STATUS |
| 255 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 256 |
//! |
| 257 |
MOS_STATUS FreeBrcResources(); |
| 258 |
|
| 259 |
//! |
| 260 |
//! \brief Free ENC resources |
| 261 |
//! |
| 262 |
//! \return MOS_STATUS |
| 263 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 264 |
//! |
| 265 |
MOS_STATUS FreeEncResources(); |
| 266 |
|
| 267 |
//! |
| 268 |
//! \brief Check profile and level |
| 269 |
//! \details Check if the required profile and level are supported by driver |
| 270 |
//! |
| 271 |
//! \return MOS_STATUS |
| 272 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 273 |
//! |
| 274 |
MOS_STATUS CheckProfileAndLevel(); |
| 275 |
|
| 276 |
//! |
| 277 |
//! \brief Setup/configure encoder based on sequence parameter set |
| 278 |
//! \details It is invoked when the encoder receives a new sequence parameter set and it would |
| 279 |
//! set up and configure the encoder state that used for the sequence |
| 280 |
//! |
| 281 |
//! \return MOS_STATUS |
| 282 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 283 |
//! |
| 284 |
MOS_STATUS SetSequenceStructs(); |
| 285 |
|
| 286 |
//! |
| 287 |
//! \brief Setup/configure encoder based on picture parameter set |
| 288 |
//! \details It is invoked for every picture and it would set up and configure the |
| 289 |
// encoder state that used for current picture |
| 290 |
//! |
| 291 |
//! \return MOS_STATUS |
| 292 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 293 |
//! |
| 294 |
MOS_STATUS SetPictureStructs(); |
| 295 |
|
| 296 |
//! |
| 297 |
//! \brief Setup/configure Slice Group |
| 298 |
//! \details It is invoked for every picture and it would set up and configure the |
| 299 |
// encoder state that used for current picture |
| 300 |
//! |
| 301 |
//! \return MOS_STATUS |
| 302 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 303 |
//! |
| 304 |
MOS_STATUS SetSliceGroups(); |
| 305 |
|
| 306 |
//! |
| 307 |
//! \brief Get current byte offset |
| 308 |
//! \details Get current byte offset for the bit stream buffer |
| 309 |
//! \param bsBuffer |
| 310 |
//! [in] Bit stream buffer |
| 311 |
//! \return uint32_t |
| 312 |
//! Byte offset |
| 313 |
//! |
| 314 |
uint32_t GetCurByteOffset(BSBuffer* bsBuffer); |
| 315 |
|
| 316 |
//! |
| 317 |
//! \brief Pack display sequence extension |
| 318 |
//! \details Pack display sequence extension, MPEG2 Spec 6.2.2.4 |
| 319 |
//! |
| 320 |
//! \return MOS_STATUS |
| 321 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 322 |
MOS_STATUS PackDisplaySeqExtension(); |
| 323 |
|
| 324 |
//! |
| 325 |
//! \brief Pack sequence extension |
| 326 |
//! \details Pack sequence extension, MPEG2 Spec 6.2.2.3 |
| 327 |
//! |
| 328 |
//! \return MOS_STATUS |
| 329 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 330 |
MOS_STATUS PackSeqExtension(); |
| 331 |
|
| 332 |
//! |
| 333 |
//! \brief Pack sequence header |
| 334 |
//! \details Pack sequence extension |
| 335 |
//! |
| 336 |
//! \return MOS_STATUS |
| 337 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 338 |
MOS_STATUS PackSeqHeader(); |
| 339 |
|
| 340 |
//! |
| 341 |
//! \brief Pack sequence parameters |
| 342 |
//! \details Pack sequence parameters |
| 343 |
//! |
| 344 |
//! \return MOS_STATUS |
| 345 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 346 |
MOS_STATUS PackSequenceParams(); |
| 347 |
|
| 348 |
//! |
| 349 |
//! \brief Pack picture coding extension |
| 350 |
//! \details Pack picture coding extension, MPEG2 Spec 6.2.3.1 |
| 351 |
//! |
| 352 |
//! \return MOS_STATUS |
| 353 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 354 |
MOS_STATUS PackPicCodingExtension(); |
| 355 |
|
| 356 |
//! |
| 357 |
//! \brief Pack picture user data |
| 358 |
//! \details Pack picture user data |
| 359 |
//! |
| 360 |
//! \return MOS_STATUS |
| 361 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 362 |
MOS_STATUS PackPicUserData(); |
| 363 |
|
| 364 |
//! |
| 365 |
//! \brief Pack picture header |
| 366 |
//! \details Pack picture header, MPEG2 Spec 6.2.3 |
| 367 |
//! |
| 368 |
//! \return MOS_STATUS |
| 369 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 370 |
MOS_STATUS PackPicHeader(); |
| 371 |
|
| 372 |
//! |
| 373 |
//! \brief Pack group of pictures header |
| 374 |
//! \details Pack group of pictures header, MPEG2 Spec 6.2.2.6 |
| 375 |
//! |
| 376 |
//! \return MOS_STATUS |
| 377 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 378 |
MOS_STATUS PackGroupOfPicHeader(); |
| 379 |
|
| 380 |
//! |
| 381 |
//! \brief Pack picture paramters |
| 382 |
//! \details Pack icture paramters |
| 383 |
//! |
| 384 |
//! \return MOS_STATUS |
| 385 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 386 |
MOS_STATUS PackPictureParams(); |
| 387 |
|
| 388 |
//! |
| 389 |
//! \brief Pack Picture Header |
| 390 |
//! \details Function to Pack Picture Header |
| 391 |
//! |
| 392 |
//! \return MOS_STATUS |
| 393 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 394 |
MOS_STATUS PackPictureHeader(); |
| 395 |
|
| 396 |
//! |
| 397 |
//! \brief Pack skip slice data |
| 398 |
//! \details Function to pack skip slice data |
| 399 |
//! |
| 400 |
//! \return MOS_STATUS |
| 401 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 402 |
MOS_STATUS PackSkipSliceData(); |
| 403 |
|
| 404 |
//! |
| 405 |
//! \brief Pack skipped MB |
| 406 |
//! \details Function to pack skipped MB |
| 407 |
//! \param [in] mbIncrement |
| 408 |
//! Number MBs for slice |
| 409 |
//! |
| 410 |
//! \return MOS_STATUS |
| 411 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 412 |
MOS_STATUS PackSkippedMB(uint32_t mbIncrement); |
| 413 |
|
| 414 |
//! |
| 415 |
//! \brief Invoke ME kernel |
| 416 |
//! |
| 417 |
//! \return MOS_STATUS |
| 418 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 419 |
//! |
| 420 |
virtual MOS_STATUS EncodeMeKernel(); |
| 421 |
|
| 422 |
//! |
| 423 |
//! \brief Calculate frame rate value |
| 424 |
//! |
| 425 |
//! \param [in] frameRateCode |
| 426 |
//! Frame rate code |
| 427 |
//! \param [in] factor |
| 428 |
//! factor |
| 429 |
//! |
| 430 |
//! \return uint32_t |
| 431 |
//! Frame rate value |
| 432 |
//! |
| 433 |
uint32_t CalcFrameRateValue(uint16_t frameRateCode, uint32_t factor); |
| 434 |
|
| 435 |
//! |
| 436 |
//! \brief Setup Curbe for BRC Init/Reset kernel |
| 437 |
//! |
| 438 |
//! \return MOS_STATUS |
| 439 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 440 |
//! |
| 441 |
MOS_STATUS SetCurbeBrcInitReset(); |
| 442 |
|
| 443 |
//! |
| 444 |
//! \brief Send surfaces BRC Init/Reset kernel |
| 445 |
//! |
| 446 |
//! \param [in] cmdBuffer |
| 447 |
//! Pointer to command buffer |
| 448 |
//! |
| 449 |
//! \return MOS_STATUS |
| 450 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 451 |
//! |
| 452 |
MOS_STATUS SendBrcInitResetSurfaces(PMOS_COMMAND_BUFFER cmdBuffer); |
| 453 |
|
| 454 |
//! |
| 455 |
//! \brief Invoke BRC Init/Reset kernel |
| 456 |
//! |
| 457 |
//! \return MOS_STATUS |
| 458 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 459 |
//! |
| 460 |
MOS_STATUS EncodeBrcInitResetKernel(); |
| 461 |
|
| 462 |
//! |
| 463 |
//! \brief Top level function for invoking MBenc kernel |
| 464 |
//! |
| 465 |
//! \param [in] mbEncIFrameDistEnabled |
| 466 |
//! Indicate if MbEnc I-Frame distortion is enabled |
| 467 |
//! |
| 468 |
//! \return MOS_STATUS |
| 469 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 470 |
//! |
| 471 |
MOS_STATUS EncodeMbEncKernel(bool mbEncIFrameDistEnabled); |
| 472 |
|
| 473 |
//! |
| 474 |
//! \brief Send surfaces for BRC Update kernel |
| 475 |
//! |
| 476 |
//! \param [in] cmdBuffer |
| 477 |
//! Pointer to command buffer |
| 478 |
//! \return MOS_STATUS |
| 479 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 480 |
//! |
| 481 |
MOS_STATUS SendBrcUpdateSurfaces(PMOS_COMMAND_BUFFER cmdBuffer); |
| 482 |
|
| 483 |
//! |
| 484 |
//! \brief Setup Curbe for BRC Update kernel |
| 485 |
//! |
| 486 |
//! \return MOS_STATUS |
| 487 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 488 |
//! |
| 489 |
MOS_STATUS SetCurbeBrcUpdate(); |
| 490 |
|
| 491 |
//! |
| 492 |
//! \brief Initialize for BRC constant buffer |
| 493 |
//! |
| 494 |
//! \return MOS_STATUS |
| 495 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 496 |
//! |
| 497 |
MOS_STATUS InitBrcConstantBuffer(); |
| 498 |
|
| 499 |
//! |
| 500 |
//! \brief Invoke BRC update kernel |
| 501 |
//! |
| 502 |
//! \return MOS_STATUS |
| 503 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 504 |
//! |
| 505 |
MOS_STATUS EncodeBrcUpdateKernel(); |
| 506 |
|
| 507 |
//! |
| 508 |
//! \brief Send Slice parameters |
| 509 |
//! |
| 510 |
//! \param [in] cmdBuffer |
| 511 |
//! Pointer to command buffer |
| 512 |
//! \param [in] params |
| 513 |
//! Pointer to PMHW_VDBOX_MPEG2_SLICE_STATE |
| 514 |
//! |
| 515 |
//! \return MOS_STATUS |
| 516 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 517 |
//! |
| 518 |
MOS_STATUS SendSliceParams( |
| 519 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 520 |
PMHW_VDBOX_MPEG2_SLICE_STATE params); |
| 521 |
|
| 522 |
//! |
| 523 |
//! \brief Send Surfaces for MbEnc kernel |
| 524 |
//! |
| 525 |
//! \param [in] cmdBuffer |
| 526 |
//! Pointer to command buffer |
| 527 |
//! \param [in] mbEncIFrameDistEnabled |
| 528 |
//! Indicate if MbEnc I-Frame distortion is enabled |
| 529 |
//! |
| 530 |
//! \return MOS_STATUS |
| 531 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 532 |
//! |
| 533 |
virtual MOS_STATUS SendMbEncSurfaces( |
| 534 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 535 |
bool mbEncIFrameDistEnabled); |
| 536 |
|
| 537 |
//! |
| 538 |
//! \brief Initialize kernel state |
| 539 |
//! |
| 540 |
//! \return MOS_STATUS |
| 541 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 542 |
//! |
| 543 |
virtual MOS_STATUS InitKernelState() = 0; |
| 544 |
|
| 545 |
//! |
| 546 |
//! \brief Get maximum BT count |
| 547 |
//! |
| 548 |
//! \return uint32_t |
| 549 |
//! Maximum BT count |
| 550 |
//! |
| 551 |
virtual uint32_t GetMaxBtCount(); |
| 552 |
|
| 553 |
//! |
| 554 |
//! \brief Prepare the Curbe for ME kernel |
| 555 |
//! |
| 556 |
//! \return MOS_STATUS |
| 557 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 558 |
//! |
| 559 |
virtual MOS_STATUS SetCurbeMe() |
| 560 |
{ |
| 561 |
// No operations when m_hmeKernel exists |
| 562 |
return MOS_STATUS_SUCCESS; |
| 563 |
} |
| 564 |
|
| 565 |
//! |
| 566 |
//! \brief Send surfaces to the ME kernel |
| 567 |
//! |
| 568 |
//! \param [in] cmdBuffer |
| 569 |
//! Pointer to command buffer |
| 570 |
//! |
| 571 |
//! \return MOS_STATUS |
| 572 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 573 |
//! |
| 574 |
virtual MOS_STATUS SendMeSurfaces(PMOS_COMMAND_BUFFER cmdBuffer) |
| 575 |
{ |
| 576 |
// No operations when m_hmeKernel exists |
| 577 |
return MOS_STATUS_SUCCESS; |
| 578 |
} |
| 579 |
|
| 580 |
//! |
| 581 |
//! \brief Setup Curbe for MbEnc Kernels |
| 582 |
//! |
| 583 |
//! \param [in] mbEncIFrameDistEnabled |
| 584 |
//! Indicate if MbEnc I-Frame distortion is enabled |
| 585 |
//! \param [in] mbQpDataEnabled |
| 586 |
//! Indicate if MB QP data is enabled |
| 587 |
//! |
| 588 |
//! \return MOS_STATUS |
| 589 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 590 |
//! |
| 591 |
virtual MOS_STATUS SetCurbeMbEnc( |
| 592 |
bool mbEncIFrameDistEnabled, |
| 593 |
bool mbQpDataEnabled) = 0; |
| 594 |
|
| 595 |
//! |
| 596 |
//! \brief Initialize BRC kernel state |
| 597 |
//! |
| 598 |
//! \return MOS_STATUS |
| 599 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 600 |
//! |
| 601 |
virtual MOS_STATUS InitKernelStateBrc(); |
| 602 |
|
| 603 |
//! |
| 604 |
//! \brief Update the slice count according to the DymanicSliceShutdown policy |
| 605 |
//! |
| 606 |
virtual void UpdateSSDSliceCount(); |
| 607 |
|
| 608 |
#if USE_CODECHAL_DEBUG_TOOL |
| 609 |
MOS_STATUS DumpSeqParams( |
| 610 |
CodecEncodeMpeg2SequenceParams *seqParams); |
| 611 |
|
| 612 |
MOS_STATUS DumpPicParams( |
| 613 |
CodecEncodeMpeg2PictureParams *picParams); |
| 614 |
|
| 615 |
MOS_STATUS DumpSliceParams( |
| 616 |
CodecEncodeMpeg2SliceParmas *sliceParams); |
| 617 |
|
| 618 |
MOS_STATUS DumpVuiParams( |
| 619 |
CodecEncodeMpeg2VuiParams *vuiParams); |
| 620 |
#endif |
| 621 |
//! |
| 622 |
//! \enum MbEncKernelStateIdx |
| 623 |
//! \brief MbEnc kernel index |
| 624 |
//! |
| 625 |
enum MbEncKernelStateIdx |
| 626 |
{ |
| 627 |
mbEncKernelIdxI = 0, |
| 628 |
mbEncKernelIdxP, |
| 629 |
mbEncKernelIdxB, |
| 630 |
mbEncKernelIdxNum, |
| 631 |
}; |
| 632 |
|
| 633 |
//! |
| 634 |
//! \struct BindingTableMbEnc |
| 635 |
//! \brief MbEnc binding table r structure |
| 636 |
//! |
| 637 |
struct BindingTableMbEnc |
| 638 |
{ |
| 639 |
uint32_t m_mbEncPakObj; |
| 640 |
uint32_t m_mbEncPakObjPrev; |
| 641 |
uint32_t m_mbEncCurrentY; |
| 642 |
uint32_t m_mbEncBrcDistortionSurface; |
| 643 |
uint32_t m_mbEncCurrentPic; |
| 644 |
uint32_t m_mbEncForwardPic; |
| 645 |
uint32_t m_mbEncBackwardPic; |
| 646 |
uint32_t m_mbEncInterlaceFrameCurrentPic; |
| 647 |
uint32_t m_mbEncInterlaceFrameBackwardPic; |
| 648 |
uint32_t m_mbEncMbControl; |
| 649 |
uint32_t m_mbEncScoreboard; |
| 650 |
}; |
| 651 |
|
| 652 |
static const uint32_t m_numSyncTags = 36; //!< Number of kernels: per frame & kernel workload |
| 653 |
static const uint32_t m_initDshSize = MHW_PAGE_SIZE * 2; //!< Perfomance tuning might be needed depending on curbe size |
| 654 |
static const uint32_t m_frameRateDenom = 100; //!< Frame rate denom |
| 655 |
static const uint32_t m_frameThresholdArraySize = 64; //!< Frame threadold array size |
| 656 |
static const uint32_t m_distQpAdjustmentArraySize = 96; //!< QP adjustemnt array size |
| 657 |
static const uint32_t m_brcConstantSurfaceWidth = 64; //!< BRC constant surface width |
| 658 |
static const uint32_t m_brcPicHeaderSurfaceSize = 1024; //!< BRC picture header surface size |
| 659 |
static const uint32_t m_brcHistoryBufferSize = 576; //!< BRC history buffer size |
| 660 |
static const uint32_t m_targetUsageNum = 8; //!< Target usage number |
| 661 |
static const uint32_t m_maxVmvr = 128 * 4; //!< Max VMVR |
| 662 |
static const uint32_t m_mvCostTableOffset = 52; //!< MV cost table offset |
| 663 |
|
| 664 |
static const uint8_t m_qpAdjustmentDistThresholdMaxFrameThresholdI[m_frameThresholdArraySize];//!< QP adjustment threashold array for I frame |
| 665 |
static const uint8_t m_qpAdjustmentDistThresholdMaxFrameThresholdP[m_frameThresholdArraySize];//!< QP adjustment threashold array for P frame |
| 666 |
static const uint8_t m_qpAdjustmentDistThresholdMaxFrameThresholdB[m_frameThresholdArraySize];//!< QP adjustment threashold array for B frame |
| 667 |
static const uint8_t m_distQpAdjustmentI[m_distQpAdjustmentArraySize]; //!< QP adjustment array for I frame |
| 668 |
static const uint8_t m_distQpAdjustmentP[m_distQpAdjustmentArraySize]; //!< QP adjustment array for P frame |
| 669 |
static const uint8_t m_distQpAdjustmentB[m_distQpAdjustmentArraySize]; //!< QP adjustment array for B frame |
| 670 |
static const uint8_t m_targetUsageToKernelMode[m_targetUsageNum]; //!< Table for target usage to kernel mode convert |
| 671 |
|
| 672 |
static const uint32_t m_vmeLutXyP[2]; //!< vme LUT XY table for P frame |
| 673 |
static const uint32_t m_vmeLutXyB[2]; //!< vme LUT XY table for B frame |
| 674 |
static const uint32_t m_vmeSPathP0[16]; //!< vme search path table 0 for P frame |
| 675 |
static const uint32_t m_vmeSPathP1[16]; //!< vme search path table 1 for P frame |
| 676 |
static const uint32_t m_vmeSPathB0[16]; //!< vme search path table 0 for B frame |
| 677 |
static const uint32_t m_vmeSPathB1[16]; //!< vme search path table 1 for B frame |
| 678 |
|
| 679 |
CodecEncodeMpeg2SequenceParams *m_seqParams = nullptr; //!< Pointer to sequence parameter |
| 680 |
CodecEncodeMpeg2VuiParams *m_vuiParams = nullptr; //!< Pointer to vui parameter |
| 681 |
CodecEncodeMpeg2SliceParmas *m_sliceParams = nullptr; //!< Pointer to slice parameter |
| 682 |
CodecEncodeMpeg2QmatixParams *m_qMatrixParams = nullptr; //!< Pointer to qmatrix parameter |
| 683 |
CODEC_PIC_ID m_picIdx[CODEC_MAX_NUM_REF_FRAME_NON_AVC]; //!< Picture index |
| 684 |
|
| 685 |
uint8_t* m_kernelBinary = nullptr; //!< Pointer to the kernel binary |
| 686 |
uint32_t m_combinedKernelSize = 0; //!< Combined kernel binary size |
| 687 |
|
| 688 |
bool m_sliceStateEnable = true; //!< Indicate if slice state is enabled |
| 689 |
|
| 690 |
// BRC |
| 691 |
bool m_brcInit = true; //!< Indicate if BRC is initilized |
| 692 |
bool m_mbEncCurbeSetInBrcUpdate = false; //!< Indicatd if Mbenc curbe is set |
| 693 |
bool m_brcEnabled = false; //!< Indicate if BRC is enabled |
| 694 |
bool m_brcReset = false; //!< Indicate if BRC is reset |
| 695 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 696 |
bool m_brcDistortionBufferSupported = false; //!< Indicate if BRC distorion buffer is supported |
| 697 |
#endif |
| 698 |
uint16_t m_avbrAccuracy = 0; //!< AVBR Accuracy |
| 699 |
uint16_t m_avbrConvergence = 0; //!< AVBR Convergence |
| 700 |
uint32_t m_picHeaderDataBufferSize = 0; //!< Picture header buffer size |
| 701 |
uint32_t m_qScaleTypeByteOffse = 0; //!< Offset for QScle |
| 702 |
uint32_t m_vbvDelayOffset = 0; //!< Offset for Vbv delay |
| 703 |
uint32_t m_intraDcPrecisionOffset = 0; //!< Offset for Intra DC precision |
| 704 |
MHW_KERNEL_STATE m_brcKernelStates[CODECHAL_ENCODE_BRC_IDX_NUM]; //!< BRC kernel state |
| 705 |
EncodeBrcBuffers m_brcBuffers; //!< BRC buffers |
| 706 |
double m_brcInitCurrentTargetBufFullInBits = 0; //!< BRC init buffer full |
| 707 |
double m_brcInitResetInputBitsPerFrame = 0; //!< BRC init reset input bits per frame |
| 708 |
double m_brcInitResetBufSizeInBits = 0; //!< BRC init reset buffer size |
| 709 |
|
| 710 |
// MbEnc |
| 711 |
bool m_mbQpDataEnabled = false; //!< Mb Qp data flag |
| 712 |
MOS_SURFACE m_mbQpDataSurface; //!< MOS_SURFACE of Mb Qp data surface |
| 713 |
uint32_t m_frameNumB = 0; //!< The num of the successive B frames |
| 714 |
uint32_t m_prevMBCodeIdx = 0; //!< Previous MB Code index // MbEnc |
| 715 |
uint8_t m_mbEncForcePictureCodingType = 0; //!< force I, P, or B for MbEnc kernel only |
| 716 |
MHW_KERNEL_STATE m_mbEncKernelStates[mbEncKernelIdxNum]; //!< MbEnc kernel state |
| 717 |
BindingTableMbEnc m_mbEncBindingTable; //!< MbEnc binding table |
| 718 |
|
| 719 |
// ME |
| 720 |
CodechalKernelHme *m_hmeKernel = nullptr; //!< ME kernel object |
| 721 |
bool m_hmeEnabled = false; //!< HME enable flag |
| 722 |
MOS_SURFACE m_4xMEMVDataBuffer; //!< 4xME mv data buffer |
| 723 |
MHW_BATCH_BUFFER m_batchBufForMEDistBuffer[NUM_ENCODE_BB_TYPE]; //!< ME Distortion batch buffer for ME call |
| 724 |
uint32_t m_memvBottomFieldOffset = 0; //!< MEMV bottom filed offset |
| 725 |
MOS_SURFACE m_4xMEDistortionBuffer; //!< MOS_SURFACE of ME distortion surface |
| 726 |
uint32_t m_meDistortionBottomFieldOffset = 0; //!< ME distortion bottom filed offset |
| 727 |
|
| 728 |
private: |
| 729 |
//! |
| 730 |
//! \brief Walker function |
| 731 |
//! |
| 732 |
void MBWalker(uint16_t, uint16_t, uint16_t*); |
| 733 |
void MBWalker45Degree(uint16_t, uint16_t, uint16_t*); |
| 734 |
void MBWalkerMBAFF(uint16_t, uint16_t, uint16_t*); |
| 735 |
void MBWalkerRasterScan(uint16_t, uint16_t, uint16_t*); |
| 736 |
void MBWalkerVerticalScan(uint16_t, uint16_t, uint16_t*); |
| 737 |
}; |
| 738 |
|
| 739 |
#endif // __CODECHAL_ENCODE_MPEG2_H__ |