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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
|
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file media_ddi_encode_base.h
//! \brief Defines base class for DDI media encode.
//!
#ifndef __MEDIA_DDI_ENCODE_BASE_H__
#define __MEDIA_DDI_ENCODE_BASE_H__
#include <va/va.h>
#include "media_ddi_base.h"
#include "media_libva_encoder.h"
#include "codechal_setting.h"
//!
//! \class DdiEncodeBase
//! \brief Ddi encode base
//!
class DdiEncodeBase : public DdiMediaBase
{
public:
//! \brief chroma format
enum ChromaFormat
{
monochrome = 0,
yuv420 = 1,
yuv422 = 2,
yuv444 = 3
};
//!
//! \brief Constructor
//!
DdiEncodeBase();
//!
//! \brief Initialize the encode context and do codechal setting
//! \details Allocate memory for pointer members of encode context, set codechal
//! which used by Codechal::Allocate
//!
//! \param [out] codecHalSettings
//! CodechalSetting *
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if success, else fail reason
//!
virtual VAStatus ContextInitialize(CodechalSetting * codecHalSettings) = 0;
//!
//! \brief Destructor
//!
virtual ~DdiEncodeBase()
{
MOS_Delete(m_codechalSettings);
m_codechalSettings = nullptr;
};
virtual VAStatus BeginPicture(
VADriverContextP ctx,
VAContextID context,
VASurfaceID renderTarget);
virtual VAStatus RenderPicture(
VADriverContextP ctx,
VAContextID context,
VABufferID * buffers,
int32_t numBuffers) = 0;
virtual VAStatus EndPicture(
VADriverContextP ctx,
VAContextID context);
//!
//! \brief Report Status for coded buffer.
//!
//! \param [in] mediaBuf
//! Pointer to DDI_MEDIA_BUFFER
//! \param [out] buf
//! Pointer to buffer
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if success, else fail reason
//!
virtual VAStatus StatusReport(
DDI_MEDIA_BUFFER *mediaBuf,
void **buf);
//!
//! \brief Report Status for Enc buffer.
//!
//! \param [in] mediaBuf
//! Pointer to DDI_MEDIA_BUFFER
//! \param [out] buf
//! Pointer to buffer
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if success, else fail reason
//!
VAStatus EncStatusReport(
DDI_MEDIA_BUFFER *mediaBuf,
void **buf);
//!
//! \brief Report Status for PreEnc buffer.
//!
//! \param [in] mediaBuf
//! Pointer to DDI_MEDIA_BUFFER
//! \param [out] buf
//! Pointer to buffer
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if success, else fail reason
//!
VAStatus PreEncStatusReport(
DDI_MEDIA_BUFFER *mediaBuf,
void **buf);
//!
//! \brief Remove Report Status from status report list.
//!
//! \param [in] buf
//! Pointer to DDI_MEDIA_BUFFER
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if success, else fail reason
//!
VAStatus RemoveFromStatusReportQueue(DDI_MEDIA_BUFFER *buf);
//!
//! \brief Remove Enc Report Status from status report list.
//!
//! \param [in] buf
//! Pointer to DDI_MEDIA_BUFFER
//! \param [in] typeIdx
//! FEI Enc buffer type
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if success, else fail reason
//!
VAStatus RemoveFromEncStatusReportQueue(
DDI_MEDIA_BUFFER *buf,
DDI_ENCODE_FEI_ENC_BUFFER_TYPE typeIdx);
//!
//! \brief Remove PreEnc Report Status from status report list.
//!
//! \param [in] buf
//! Pointer to DDI_MEDIA_BUFFER
//! \param [in] typeIdx
//! PreEnc buffer type
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if success, else fail reason
//!
VAStatus RemoveFromPreEncStatusReportQueue(
DDI_MEDIA_BUFFER *buf,
DDI_ENCODE_PRE_ENC_BUFFER_TYPE typeIdx);
//!
//! \brief Check if coded buffer exist in status report list
//!
//! \param [in] buf
//! Pointer to DDI_MEDIA_BUFFER
//!
//! \return bool
//! true if exist, else false
//!
bool CodedBufferExistInStatusReport(DDI_MEDIA_BUFFER *buf);
//!
//! \brief Check if Enc buffer exist in status report list
//!
//! \param [in] buf
//! Pointer to DDI_MEDIA_BUFFER
//! \param [in] typeIdx
//! FEI Enc buffer type
//!
//! \return bool
//! true if exist, else false
//!
bool EncBufferExistInStatusReport(
DDI_MEDIA_BUFFER *buf,
DDI_ENCODE_FEI_ENC_BUFFER_TYPE typeIdx);
//!
//! \brief Check if PreEnc buffer exist in status report list
//!
//! \param [in] buf
//! Pointer to DDI_MEDIA_BUFFER
//! \param [in] typeIdx
//! PreEnc buffer type
//!
//! \return bool
//! true if exist, else false
//!
bool PreEncBufferExistInStatusReport(
DDI_MEDIA_BUFFER *buf,
DDI_ENCODE_PRE_ENC_BUFFER_TYPE typeIdx);
//!
//! \brief Create Encode buffer
//! \details Create Encode buffer
//!
//! \param [in] ctx
//! Pointer to VA Driver Context
//! \param [in] type
//! Va Buffer type
//! \param [in] size
//! Size of each element in buffer
//! \param [in] elementsNum
//! Number of elements
//! \param [in] data
//! Buffer data
//! \param [in] bufId
//! Pointer to VABufferID
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if successful, else fail reason
//!
VAStatus CreateBuffer(
VADriverContextP ctx,
VABufferType type,
uint32_t size,
uint32_t elementsNum,
void *data,
VABufferID *bufId);
//!
//! \brief Init comp buffer
//! \details Init comp buffer
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if successful, else fail reason
//!
virtual VAStatus InitCompBuffer();
//!
//! \brief Free comp buffer
//! \details Free comp buffer
//!
//! \return void
//!
virtual void FreeCompBuffer();
DDI_ENCODE_CONTEXT *m_encodeCtx = nullptr; //!< The referred DDI_ENCODE_CONTEXT object.
bool m_is10Bit = false; //!< 10 bit flag.
ChromaFormat m_chromaFormat = yuv420; //!< HCP chroma format.
CodechalSetting *m_codechalSettings = nullptr; //!< Codechal Settings
protected:
//!
//! \brief Do Encode in codechal
//! \details Prepare encode parameters, surfaces and buffers and submit
//! to codechal to do encoding
//!
//! \param [in] numSlices
//! Number of slices
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if successful, else fail reason
//!
virtual VAStatus EncodeInCodecHal(uint32_t numSlices) = 0;
//!
//! \brief Reset the parameters before each frame
//! \details Called by BeginPicture, reset sps parameter, bsbuffer,
//! packed header information, etc
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if successful, else fail reason
//!
virtual VAStatus ResetAtFrameLevel() = 0;
//!
//! \brief Parse picture params
//! \details Parse picture params called by RenderPicture
//!
//! \param [in] mediaCtx
//! Pointer to DDI_MEDIA_CONTEXT
//! \param [in] ptr
//! Pointer to buffer VAEncPictureParameterBufferH264
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if successful, else fail reason
//!
virtual VAStatus ParsePicParams(
DDI_MEDIA_CONTEXT *mediaCtx,
void * ptr) = 0;
//!
//! \brief Clear picture params
//! \details Clear picture params called by EndPicture
//!
//! \return void
//!
virtual void ClearPicParams();
//!
//! \brief get Slice Parameter Buffer Size
//!
//! \return uint32_t
//! Slice Parameter Buffer Size
//!
virtual uint32_t getSliceParameterBufferSize();
//!
//! \brief get Sequence Parameter Buffer Size
//!
//! \return uint32_t
//! Sequence Parameter Buffer Size
//!
virtual uint32_t getSequenceParameterBufferSize();
//!
//! \brief get Picture Parameter Buffer Size
//!
//! \return uint32_t
//! Picture Parameter Buffer Size
//!
virtual uint32_t getPictureParameterBufferSize();
//!
//! \brief get QMatrix Parameter Buffer Size
//!
//! \return uint32_t
//! QMatrix Parameter Buffer Size
//!
virtual uint32_t getQMatrixBufferSize();
//!
//! \brief Add coded buffer information
//! \details Add coded buffer information to Status Report Queue. this function
//! called by RenderPicture
//!
//! \param [in] codedBuf
//! Pointer to Coded buffer
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if successful, else fail reason
//!
VAStatus AddToStatusReportQueue(void *codedBuf);
//!
//! \brief Convert rate control method in VAAPI to the term in HAL
//!
//! \param [in] vaRC
//! Rate control method in VAAPI
//!
//! \return uint8_t
//! Rate control method in HAL
//!
uint8_t VARC2HalRC(uint32_t vaRC);
//!
//! \brief Update status report buffer
//! \details When we get coded buffer's size at StatusReport, update the size to Status
//! Report Buffer. There should be some buffers waiting to be updated which
//! are added in AddToStatusReportQueue.
//!
//! \param [in] size
//! Coded buffer's size
//! \param [in] status
//! Buffer status
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if successful, else fail reason
//!
VAStatus UpdateStatusReportBuffer(
uint32_t size,
uint32_t status);
//!
//! \brief Update Enc status report buffer
//! \details There should be some buffers waiting to be updated which
//! are added in AddToEncStatusReportQueue.
//!
//! \param [in] status
//! Buffer status
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if successful, else fail reason
//!
VAStatus UpdateEncStatusReportBuffer(uint32_t status);
//!
//! \brief Update PreEnc status report buffer
//! \details There should be some buffers waiting to be updated which
//! are added in AddToPreEncStatusReportQueue.
//!
//! \param [in] status
//! Buffer status
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if successful, else fail reason
//!
VAStatus UpdatePreEncStatusReportBuffer(uint32_t status);
//!
//! \brief Get Size From Status Report Buffer
//! \details Get the coded buffer size, status and the index from Status
//! Report Queue when we can match the input buffer.
//!
//! \param [in] buf
//! Pointer to DDI_MEDIA_BUFFER
//! \param [out] size
//! Pointer to uint32_t
//! \param [out] status
//! Pointer to uint32_t
//! \param [out] index
//! Pointer to int32_t
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if successful, else fail reason
//!
VAStatus GetSizeFromStatusReportBuffer(
DDI_MEDIA_BUFFER *buf,
uint32_t *size,
uint32_t *status,
int32_t *index);
//!
//! \brief Get Index From Enc Status Report Buffer
//! \details Get the Enc buffer status and the index from Status
//! Report Queue when we can match the input buffer.
//!
//! \param [in] buf
//! Pointer to DDI_MEDIA_BUFFER
//! \param [in] typeIdx
//! FEI Enc buffer type
//! \param [out] status
//! Pointer to uint32_t
//! \param [out] index
//! Pointer to int32_t
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if successful, else fail reason
//!
VAStatus GetIndexFromEncStatusReportBuffer(
DDI_MEDIA_BUFFER *buf,
DDI_ENCODE_FEI_ENC_BUFFER_TYPE typeIdx,
uint32_t *status,
int32_t *index);
//!
//! \brief Get Index From PreEnc Status Report Buffer
//! \details Get the PreEnc buffer status and the index from Status
//! Report Queue when we can match the input buffer.
//!
//! \param [in] buf
//! Pointer to DDI_MEDIA_BUFFER
//! \param [in] typeIdx
//! PreEnc buffer type
//! \param [out] status
//! Pointer to uint32_t
//! \param [out] index
//! Pointer to int32_t
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if successful, else fail reason
//!
VAStatus GetIndexFromPreEncStatusReportBuffer(
DDI_MEDIA_BUFFER *buf,
DDI_ENCODE_PRE_ENC_BUFFER_TYPE typeIdx,
uint32_t *status,
int32_t *index);
//!
//! \brief Report extra encode status for completed coded buffer.
//!
//! \param [in] encodeStatusReport
//! Pointer to encode status reported by Codechal
//! \param [out] codedBufferSegment
//! Pointer to coded buffer segment
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if success, else fail reason
//!
virtual VAStatus ReportExtraStatus(
EncodeStatusReport *encodeStatusReport,
VACodedBufferSegment *codedBufferSegment)
{
return VA_STATUS_SUCCESS;
}
//!
//! \brief Clean Up Buffer and Return
//!
//! \param [in] buf
//! Pointer to DDI_MEDIA_BUFFER
//!
//! \return void
void CleanUpBufferandReturn(DDI_MEDIA_BUFFER *buf);
bool m_newSeqHeader = false; //!< Flag for new Sequence Header.
bool m_newPpsHeader = false; //!< Flag for new Pps Header.
bool m_arbitraryNumMbsInSlice = false; //!< Flag to indicate if the sliceMapSurface needs to be programmed or not.
uint8_t m_scalingLists4x4[6][16]{}; //!< Inverse quantization scale lists 4x4.
uint8_t m_scalingLists8x8[2][64]{}; //!< Inverse quantization scale lists 8x8.
};
#endif /* __MEDIA_DDI_ENCODE_BASE_H__ */
|