| 1 |
/* |
| 2 |
* Copyright (c) 2021, 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 media_libva_util_next.h |
| 24 |
//! \brief libva(and its extension) utility head file |
| 25 |
//! |
| 26 |
|
| 27 |
#ifndef __MEDIA_LIBVA_UTIL_NEXT_H__ |
| 28 |
#define __MEDIA_LIBVA_UTIL_NEXT_H__ |
| 29 |
|
| 30 |
#include "media_libva_common_next.h" |
| 31 |
#include "vp_common.h" |
| 32 |
|
| 33 |
#ifdef ANDROID |
| 34 |
#define DDI_FUNC_ENTER UMD_ATRACE_BEGIN(__FUNCTION__) |
| 35 |
#define DDI_FUNCTION_EXIT(status) UMD_ATRACE_END |
| 36 |
#else |
| 37 |
#define DDI_FUNC_ENTER \ |
| 38 |
MOS_FUNCTION_TRACE(MOS_COMPONENT_DDI, MOS_SUBCOMP_SELF) |
| 39 |
#define DDI_FUNCTION_EXIT(status) \ |
| 40 |
MOS_FUNCTION_EXIT(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF, status) |
| 41 |
#endif |
| 42 |
|
| 43 |
#define DDI_CODEC_FUNC_ENTER \ |
| 44 |
MOS_FUNCTION_TRACE(MOS_COMPONENT_DDI, MOS_SUBCOMP_CODEC) |
| 45 |
|
| 46 |
#define DDI_VP_FUNC_ENTER \ |
| 47 |
MOS_FUNCTION_TRACE(MOS_COMPONENT_DDI, MOS_SUBCOMP_VP) |
| 48 |
|
| 49 |
#define DDI_CP_FUNC_ENTER \ |
| 50 |
MOS_FUNCTION_TRACE(MOS_COMPONENT_DDI, MOS_SUBCOMP_CP) |
| 51 |
|
| 52 |
#define DDI_ASSERT(_expr) \ |
| 53 |
MOS_ASSERT(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF, _expr) |
| 54 |
|
| 55 |
#define DDI_ASSERTMESSAGE(_message, ...) \ |
| 56 |
MOS_ASSERTMESSAGE(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF, _message, ##__VA_ARGS__) |
| 57 |
|
| 58 |
#define DDI_NORMALMESSAGE(_message, ...) \ |
| 59 |
MOS_NORMALMESSAGE(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF, _message, ##__VA_ARGS__) |
| 60 |
|
| 61 |
#define DDI_VERBOSEMESSAGE(_message, ...) \ |
| 62 |
MOS_VERBOSEMESSAGE(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF, _message, ##__VA_ARGS__) |
| 63 |
|
| 64 |
#define DDI_CODEC_ASSERTMESSAGE(_message, ...) \ |
| 65 |
MOS_ASSERTMESSAGE(MOS_COMPONENT_DDI, MOS_SUBCOMP_CODEC, _message, ##__VA_ARGS__) |
| 66 |
|
| 67 |
#define DDI_CODEC_NORMALMESSAGE(_message, ...) \ |
| 68 |
MOS_NORMALMESSAGE(MOS_COMPONENT_DDI, MOS_SUBCOMP_CODEC, _message, ##__VA_ARGS__) |
| 69 |
|
| 70 |
#define DDI_CODEC_VERBOSEMESSAGE(_message, ...) \ |
| 71 |
MOS_VERBOSEMESSAGE(MOS_COMPONENT_DDI, MOS_SUBCOMP_CODEC, _message, ##__VA_ARGS__) |
| 72 |
|
| 73 |
#define DDI_VP_ASSERTMESSAGE(_message, ...) \ |
| 74 |
MOS_ASSERTMESSAGE(MOS_COMPONENT_DDI, MOS_SUBCOMP_VP, _message, ##__VA_ARGS__) |
| 75 |
|
| 76 |
#define DDI_VP_NORMALMESSAGE(_message, ...) \ |
| 77 |
MOS_NORMALMESSAGE(MOS_COMPONENT_DDI, MOS_SUBCOMP_VP, _message, ##__VA_ARGS__) |
| 78 |
|
| 79 |
#define DDI_VP_VERBOSEMESSAGE(_message, ...) \ |
| 80 |
MOS_VERBOSEMESSAGE(MOS_COMPONENT_DDI, MOS_SUBCOMP_VP, _message, ##__VA_ARGS__) |
| 81 |
|
| 82 |
#define DDI_CP_ASSERTMESSAGE(_message, ...) \ |
| 83 |
MOS_ASSERTMESSAGE(MOS_COMPONENT_DDI, MOS_SUBCOMP_CP, _message, ##__VA_ARGS__) |
| 84 |
|
| 85 |
#define DDI_CP_NORMALMESSAGE(_message, ...) \ |
| 86 |
MOS_NORMALMESSAGE(MOS_COMPONENT_DDI, MOS_SUBCOMP_CP, _message, ##__VA_ARGS__) |
| 87 |
|
| 88 |
#define DDI_CP_VERBOSEMESSAGE(_message, ...) \ |
| 89 |
MOS_VERBOSEMESSAGE(MOS_COMPONENT_DDI, MOS_SUBCOMP_CP, _message, ##__VA_ARGS__) |
| 90 |
|
| 91 |
// Check the return value of function. |
| 92 |
// If failed, print the error message and return, |
| 93 |
// do nothing otherwise. |
| 94 |
#define DDI_CHK_RET(_ret, _str) \ |
| 95 |
{ \ |
| 96 |
VAStatus tmpRet = _ret; \ |
| 97 |
if (VA_STATUS_SUCCESS != tmpRet) { \ |
| 98 |
DDI_ASSERTMESSAGE("%s [%d].", _str, tmpRet); \ |
| 99 |
return tmpRet; \ |
| 100 |
} \ |
| 101 |
} |
| 102 |
|
| 103 |
#define DDI_CODEC_CHK_RET(_ret, _str) \ |
| 104 |
{ \ |
| 105 |
VAStatus tmpRet = _ret; \ |
| 106 |
if (VA_STATUS_SUCCESS != tmpRet) { \ |
| 107 |
DDI_CODEC_ASSERTMESSAGE("%s [%d].", _str, tmpRet); \ |
| 108 |
return tmpRet; \ |
| 109 |
} \ |
| 110 |
} |
| 111 |
|
| 112 |
#define DDI_VP_CHK_RET(_ret, _str) \ |
| 113 |
{ \ |
| 114 |
VAStatus tmpRet = _ret; \ |
| 115 |
if (VA_STATUS_SUCCESS != tmpRet) { \ |
| 116 |
DDI_VP_ASSERTMESSAGE("%s [%d].", _str, tmpRet); \ |
| 117 |
return tmpRet; \ |
| 118 |
} \ |
| 119 |
} |
| 120 |
|
| 121 |
#define DDI_CP_CHK_RET(_ret, _str) \ |
| 122 |
{ \ |
| 123 |
VAStatus tmpRet = _ret; \ |
| 124 |
if (VA_STATUS_SUCCESS != tmpRet) { \ |
| 125 |
DDI_CP_ASSERTMESSAGE("%s [%d].", _str, tmpRet); \ |
| 126 |
return tmpRet; \ |
| 127 |
} \ |
| 128 |
} |
| 129 |
|
| 130 |
// Check the return status of parse function in renderPicture |
| 131 |
// If failed, assign new status and break |
| 132 |
// do nothing otherwise. |
| 133 |
#define DDI_CHK_STATUS(_ret, _newret) \ |
| 134 |
{ \ |
| 135 |
if (VA_STATUS_SUCCESS != _ret) { \ |
| 136 |
vaStatus = _newret; \ |
| 137 |
break; \ |
| 138 |
} \ |
| 139 |
} |
| 140 |
|
| 141 |
// Check the condition, if true, print the error message |
| 142 |
// and return the specified value, do nothing otherwise. |
| 143 |
#define DDI_CHK_CONDITION(condition, _str, _ret) \ |
| 144 |
if (condition) { \ |
| 145 |
DDI_ASSERTMESSAGE(_str); \ |
| 146 |
return _ret; \ |
| 147 |
} |
| 148 |
|
| 149 |
#define DDI_CODEC_CHK_CONDITION(condition, _str, _ret) \ |
| 150 |
if (condition) { \ |
| 151 |
DDI_CODEC_ASSERTMESSAGE(_str); \ |
| 152 |
return _ret; \ |
| 153 |
} |
| 154 |
|
| 155 |
#define DDI_VP_CHK_CONDITION(condition, _str, _ret) \ |
| 156 |
if (condition) { \ |
| 157 |
DDI_VP_ASSERTMESSAGE(_str); \ |
| 158 |
return _ret; \ |
| 159 |
} |
| 160 |
|
| 161 |
#define DDI_CP_CHK_CONDITION(condition, _str, _ret) \ |
| 162 |
if (condition) { \ |
| 163 |
DDI_CP_ASSERTMESSAGE(_str); \ |
| 164 |
return _ret; \ |
| 165 |
} |
| 166 |
|
| 167 |
// If pointer is nullptr, print the error message and return the specified value. |
| 168 |
#define DDI_CHK_NULL(_ptr, _str, _ret) \ |
| 169 |
DDI_CHK_CONDITION((nullptr == (_ptr)), _str, _ret) |
| 170 |
#define DDI_CODEC_CHK_NULL(_ptr, _str, _ret) \ |
| 171 |
DDI_CODEC_CHK_CONDITION((nullptr == (_ptr)), _str, _ret) |
| 172 |
#define DDI_VP_CHK_NULL(_ptr, _str, _ret) \ |
| 173 |
DDI_VP_CHK_CONDITION((nullptr == (_ptr)), _str, _ret) |
| 174 |
#define DDI_CP_CHK_NULL(_ptr, _str, _ret) \ |
| 175 |
DDI_CP_CHK_CONDITION((nullptr == (_ptr)), _str, _ret) |
| 176 |
|
| 177 |
#define DDI_CHK_LARGER(p, bottom, str, ret) \ |
| 178 |
DDI_CHK_CONDITION((p <= bottom),str,ret) |
| 179 |
#define DDI_CODEC_CHK_LARGER(p, bottom, str, ret) \ |
| 180 |
DDI_CODEC_CHK_CONDITION((p <= bottom),str,ret) |
| 181 |
#define DDI_VP_CHK_LARGER(p, bottom, str, ret) \ |
| 182 |
DDI_VP_CHK_CONDITION((p <= bottom),str,ret) |
| 183 |
#define DDI_CP_CHK_LARGER(p, bottom, str, ret) \ |
| 184 |
DDI_CP_CHK_CONDITION((p <= bottom),str,ret) |
| 185 |
|
| 186 |
#define DDI_CHK_LESS(p, upper, str, ret) \ |
| 187 |
DDI_CHK_CONDITION((p >= upper),str,ret) |
| 188 |
#define DDI_CODEC_CHK_LESS(p, upper, str, ret) \ |
| 189 |
DDI_CODEC_CHK_CONDITION((p >= upper),str,ret) |
| 190 |
#define DDI_VP_CHK_LESS(p, upper, str, ret) \ |
| 191 |
DDI_VP_CHK_CONDITION((p >= upper),str,ret) |
| 192 |
#define DDI_CP_CHK_LESS(p, upper, str, ret) \ |
| 193 |
DDI_CP_CHK_CONDITION((p >= upper),str,ret) |
| 194 |
struct MEDIA_SURFACE_ALLOCATE_PARAM |
| 195 |
{ |
| 196 |
uint32_t pitch; |
| 197 |
uint32_t tileFormat; |
| 198 |
int32_t width; |
| 199 |
int32_t height; |
| 200 |
DDI_MEDIA_FORMAT format; |
| 201 |
int32_t alignedWidth; |
| 202 |
int32_t alignedHeight; |
| 203 |
uint32_t cpTag; |
| 204 |
int memType; |
| 205 |
bool bMemCompEnable; |
| 206 |
bool bMemCompRC; |
| 207 |
}; |
| 208 |
|
| 209 |
#define LENGTH_OF_FPS_FILE_NAME 128 |
| 210 |
|
| 211 |
#ifdef ANDROID |
| 212 |
#define FPS_FILE_NAME "/mnt/sdcard/fps.txt" |
| 213 |
#else |
| 214 |
#define FPS_FILE_NAME "./fps.txt" |
| 215 |
#endif |
| 216 |
|
| 217 |
class MediaLibvaUtilNext |
| 218 |
{ |
| 219 |
private: |
| 220 |
|
| 221 |
//! |
| 222 |
//! \brief Generate gmm parameters for external surface for none comporession mode |
| 223 |
//! |
| 224 |
//! \param [out] gmmCustomParams |
| 225 |
//! gmm parameters |
| 226 |
//! \param [in] params |
| 227 |
//! surface allocate paramaters |
| 228 |
//! \param [in] mediaDrvCtx |
| 229 |
//! Pointer to ddi media context |
| 230 |
//! |
| 231 |
//! \return VAStatus |
| 232 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 233 |
//! |
| 234 |
static VAStatus GenerateGmmParamsForNoneCompressionExternalSurface( |
| 235 |
GMM_RESCREATE_CUSTOM_PARAMS &gmmCustomParams, |
| 236 |
MEDIA_SURFACE_ALLOCATE_PARAM ¶ms, |
| 237 |
PDDI_MEDIA_SURFACE mediaSurface); |
| 238 |
|
| 239 |
//! |
| 240 |
//! \brief Generate gmm parameters for external surface for comporession mode |
| 241 |
//! |
| 242 |
//! \param [out] gmmParams |
| 243 |
//! gmm parameters |
| 244 |
//! \param [in] params |
| 245 |
//! surface allocate paramaters |
| 246 |
//! \param [in] mediaDrvCtx |
| 247 |
//! Pointer to ddi media context |
| 248 |
//! |
| 249 |
//! \return VAStatus |
| 250 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 251 |
//! |
| 252 |
static VAStatus GenerateGmmParamsForCompressionExternalSurface( |
| 253 |
GMM_RESCREATE_CUSTOM_PARAMS_2 &gmmParams, |
| 254 |
MEDIA_SURFACE_ALLOCATE_PARAM ¶ms, |
| 255 |
PDDI_MEDIA_SURFACE mediaSurface, |
| 256 |
PDDI_MEDIA_CONTEXT mediaDrvCtx); |
| 257 |
|
| 258 |
//! |
| 259 |
//! \brief Init surface allocate parameters |
| 260 |
//! |
| 261 |
//! \param [out] params |
| 262 |
//! surface allocate paramaters |
| 263 |
//! \param [in] width |
| 264 |
//! surface width |
| 265 |
//! \param [in] height |
| 266 |
//! surface height |
| 267 |
//! \param [in] format |
| 268 |
//! media format |
| 269 |
//! \param [in] memType |
| 270 |
//! memory type |
| 271 |
//! \param [in] surfaceUsageHint |
| 272 |
//! surface usage hint |
| 273 |
//! |
| 274 |
//! \return void |
| 275 |
//! |
| 276 |
static void InitSurfaceAllocateParams( |
| 277 |
MEDIA_SURFACE_ALLOCATE_PARAM ¶ms, |
| 278 |
int32_t width, |
| 279 |
int32_t height, |
| 280 |
DDI_MEDIA_FORMAT format, |
| 281 |
int memType, |
| 282 |
uint32_t surfaceUsageHint); |
| 283 |
|
| 284 |
//! |
| 285 |
//! \brief Set default tileformat from media foramt |
| 286 |
//! |
| 287 |
//! \param [in] format |
| 288 |
//! DDI media surface format |
| 289 |
//! \param [in] surfaceUsageHint |
| 290 |
//! surface usage hint |
| 291 |
//! \param [in] skuTable |
| 292 |
//! Sku table |
| 293 |
//! \param [out] params |
| 294 |
//! surface allocate paramaters |
| 295 |
//! |
| 296 |
//! \return VAStatus |
| 297 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 298 |
//! |
| 299 |
static VAStatus SetDefaultTileFormat( |
| 300 |
DDI_MEDIA_FORMAT format, |
| 301 |
uint32_t surfaceUsageHint, |
| 302 |
MEDIA_FEATURE_TABLE *skuTable, |
| 303 |
MEDIA_SURFACE_ALLOCATE_PARAM ¶ms); |
| 304 |
|
| 305 |
//! |
| 306 |
//! \brief Set surface parameter from modifier |
| 307 |
//! |
| 308 |
//! \param [out] params |
| 309 |
//! surface allocate paramaters |
| 310 |
//! \param [in] modifier |
| 311 |
//! modifier from surface desc |
| 312 |
//! |
| 313 |
//! \return VAStatus |
| 314 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 315 |
//! |
| 316 |
static VAStatus SetSurfaceParameterFromModifier( |
| 317 |
MEDIA_SURFACE_ALLOCATE_PARAM ¶ms, |
| 318 |
uint64_t modifier); |
| 319 |
|
| 320 |
//! |
| 321 |
//! \brief Create external surface |
| 322 |
//! |
| 323 |
//! \param [in] params |
| 324 |
//! surface allocate paramaters |
| 325 |
//! \param [out] mediaSurface |
| 326 |
//! Pointer to ddi media surface |
| 327 |
//! \param [in] mediaDrvCtx |
| 328 |
//! Pointer to ddi media context |
| 329 |
//! |
| 330 |
//! \return VAStatus |
| 331 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 332 |
//! |
| 333 |
static VAStatus CreateExternalSurface( |
| 334 |
MEDIA_SURFACE_ALLOCATE_PARAM ¶ms, |
| 335 |
PDDI_MEDIA_SURFACE mediaSurface, |
| 336 |
PDDI_MEDIA_CONTEXT mediaDrvCtx); |
| 337 |
|
| 338 |
//! |
| 339 |
//! \brief Generate gmm parameters for internal surface |
| 340 |
//! |
| 341 |
//! \param [out] gmmParams |
| 342 |
//! gmm parameters |
| 343 |
//! \param [in] params |
| 344 |
//! surface allocate paramaters |
| 345 |
//! \param [in] mediaDrvCtx |
| 346 |
//! Pointer to ddi media context |
| 347 |
//! |
| 348 |
//! \return VAStatus |
| 349 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 350 |
//! |
| 351 |
static VAStatus GenerateGmmParamsForInternalSurface( |
| 352 |
GMM_RESCREATE_PARAMS &gmmParams, |
| 353 |
MEDIA_SURFACE_ALLOCATE_PARAM ¶ms, |
| 354 |
PDDI_MEDIA_CONTEXT mediaDrvCtx); |
| 355 |
|
| 356 |
//! |
| 357 |
//! \brief Create internal surface |
| 358 |
//! |
| 359 |
//! \param [in] params |
| 360 |
//! surface allocate paramaters |
| 361 |
//! \param [out] mediaSurface |
| 362 |
//! Pointer to ddi media surface |
| 363 |
//! \param [in] mediaDrvCtx |
| 364 |
//! Pointer to ddi media context |
| 365 |
//! |
| 366 |
//! \return VAStatus |
| 367 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 368 |
//! |
| 369 |
static VAStatus CreateInternalSurface( |
| 370 |
MEDIA_SURFACE_ALLOCATE_PARAM ¶ms, |
| 371 |
PDDI_MEDIA_SURFACE mediaSurface, |
| 372 |
PDDI_MEDIA_CONTEXT mediaDrvCtx); |
| 373 |
|
| 374 |
//! |
| 375 |
//! \brief Allocate surface |
| 376 |
//! |
| 377 |
//! \param [in] format |
| 378 |
//! Ddi media format |
| 379 |
//! \param [in] width |
| 380 |
//! Width of the region |
| 381 |
//! \param [in] height |
| 382 |
//! Height of the region |
| 383 |
//! \param [out] mediaSurface |
| 384 |
//! Pointer to ddi media surface |
| 385 |
//! \param [in] mediaDrvCtx |
| 386 |
//! Pointer to ddi media context |
| 387 |
//! |
| 388 |
//! \return VAStatus |
| 389 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 390 |
//! |
| 391 |
static VAStatus AllocateSurface( |
| 392 |
DDI_MEDIA_FORMAT format, |
| 393 |
int32_t width, |
| 394 |
int32_t height, |
| 395 |
PDDI_MEDIA_SURFACE mediaSurface, |
| 396 |
PDDI_MEDIA_CONTEXT mediaDrvCtx); |
| 397 |
|
| 398 |
//! |
| 399 |
//! \brief Swizzle surface by Hardware, current only support VEBOX |
| 400 |
//! |
| 401 |
//! \param [in] surface |
| 402 |
//! Pointer of surface |
| 403 |
//! \param [in] isDeSwizzle |
| 404 |
//! Whether it's de-swizzling or not |
| 405 |
//! Swizzling - copying from video memory to temporary buffer |
| 406 |
//! De-swizzling - copying from temporary buffer to video memory |
| 407 |
//! |
| 408 |
//! \return VAStatus |
| 409 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 410 |
//! |
| 411 |
static VAStatus SwizzleSurfaceByHW(DDI_MEDIA_SURFACE *surface, bool isDeSwizzle = false); |
| 412 |
|
| 413 |
//! |
| 414 |
//! \brief Allocate 2D buffer |
| 415 |
//! |
| 416 |
//! \param [in] height |
| 417 |
//! Height of the region |
| 418 |
//! \param [in] width |
| 419 |
//! Width of the region |
| 420 |
//! \param [out] mediaBuffer |
| 421 |
//! Pointer to ddi media buffer |
| 422 |
//! \param [in] bufmgr |
| 423 |
//! Mos buffer manager |
| 424 |
//! |
| 425 |
//! \return VAStatus |
| 426 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 427 |
//! |
| 428 |
static VAStatus Allocate2DBuffer( |
| 429 |
uint32_t height, |
| 430 |
uint32_t width, |
| 431 |
PDDI_MEDIA_BUFFER mediaBuffer, |
| 432 |
MOS_BUFMGR *bufmgr); |
| 433 |
|
| 434 |
//! |
| 435 |
//! \brief Allocate buffer |
| 436 |
//! |
| 437 |
//! \param [in] format |
| 438 |
//! Ddi media format |
| 439 |
//! \param [in] size |
| 440 |
//! Size of the region |
| 441 |
//! \param [out] mediaBuffer |
| 442 |
//! Pointer to ddi media buffer |
| 443 |
//! \param [in] bufmgr |
| 444 |
//! Mos buffer manager |
| 445 |
//! |
| 446 |
//! \return VAStatus |
| 447 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 448 |
//! |
| 449 |
static VAStatus AllocateBuffer( |
| 450 |
DDI_MEDIA_FORMAT format, |
| 451 |
int32_t size, |
| 452 |
PDDI_MEDIA_BUFFER mediaBuffer, |
| 453 |
MOS_BUFMGR *bufmgr, |
| 454 |
bool isShadowBuffer = false); |
| 455 |
|
| 456 |
public: |
| 457 |
//! |
| 458 |
//! \brief Allocate pmedia surface from heap |
| 459 |
//! |
| 460 |
//! \param [in] surfaceHeap |
| 461 |
//! Pointer to ddi media heap |
| 462 |
//! |
| 463 |
//! \return PDDI_MEDIA_SURFACE_HEAP_ELEMENT |
| 464 |
//! Pointer to ddi media surface heap element |
| 465 |
//! |
| 466 |
static PDDI_MEDIA_SURFACE_HEAP_ELEMENT AllocPMediaSurfaceFromHeap(PDDI_MEDIA_HEAP surfaceHeap); |
| 467 |
|
| 468 |
//! |
| 469 |
//! \brief Release pmedia surface from heap |
| 470 |
//! |
| 471 |
//! \param [in] surfaceHeap |
| 472 |
//! Pointer to ddi media heap |
| 473 |
//! \param [in] vaSurfaceID |
| 474 |
//! VA surface ID |
| 475 |
//! |
| 476 |
static void ReleasePMediaSurfaceFromHeap(PDDI_MEDIA_HEAP surfaceHeap, uint32_t vaSurfaceID); |
| 477 |
|
| 478 |
//! |
| 479 |
//! \brief Create surface |
| 480 |
//! |
| 481 |
//! \param [in] surface |
| 482 |
//! Ddi media surface |
| 483 |
//! \param [in] mediaDrvCtx |
| 484 |
//! Pointer to ddi media context |
| 485 |
//! |
| 486 |
//! \return VAStatus |
| 487 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 488 |
//! |
| 489 |
static VAStatus CreateSurface(DDI_MEDIA_SURFACE *surface, PDDI_MEDIA_CONTEXT mediaDrvCtx); |
| 490 |
|
| 491 |
//! |
| 492 |
//! |
| 493 |
//! Descripion: if the bo of media surface was allocated from App, |
| 494 |
//! should return true, otherwise, false. In current implemeation |
| 495 |
//! external buffer passed with pSurfDesc. |
| 496 |
//! |
| 497 |
static bool IsExternalSurface(PDDI_MEDIA_SURFACE surface); |
| 498 |
|
| 499 |
//! |
| 500 |
//! \brief convert Media Format to Gmm Format for GmmResCreate parameter. |
| 501 |
//! |
| 502 |
//! \param [in] format |
| 503 |
//! Pointer to DDI_MEDIA_FORMAT |
| 504 |
//! |
| 505 |
//! \return GMM_RESOURCE_FORMAT |
| 506 |
//! Pointer to gmm format type |
| 507 |
//! |
| 508 |
static GMM_RESOURCE_FORMAT ConvertMediaFmtToGmmFmt(DDI_MEDIA_FORMAT format); |
| 509 |
|
| 510 |
//! |
| 511 |
//! \brief Wait semaphore |
| 512 |
//! |
| 513 |
//! \param [in] sem |
| 514 |
//! Pointer to media semaphore thread |
| 515 |
//! |
| 516 |
static void WaitSemaphore(PMEDIA_SEM_T sem); |
| 517 |
|
| 518 |
//! |
| 519 |
//! \brief Try wait semaphore |
| 520 |
//! |
| 521 |
//! \param [in] sem |
| 522 |
//! Pointer to media semaphore thread |
| 523 |
//! |
| 524 |
//! \return int32_t |
| 525 |
//! Try wait for semaphore. Return 0 if success, else -1 if fail |
| 526 |
//! |
| 527 |
static int32_t TryWaitSemaphore(PMEDIA_SEM_T sem); |
| 528 |
|
| 529 |
//! |
| 530 |
//! \brief Post semaphore |
| 531 |
//! |
| 532 |
//! \param [in] sem |
| 533 |
//! Pointer to media semaphore thread |
| 534 |
//! |
| 535 |
static void PostSemaphore(PMEDIA_SEM_T sem); |
| 536 |
|
| 537 |
//! |
| 538 |
//! \brief Destroy semaphore |
| 539 |
//! |
| 540 |
//! \param [in] sem |
| 541 |
//! Pointer to media semaphore thread |
| 542 |
//! |
| 543 |
static void DestroySemaphore(PMEDIA_SEM_T sem); |
| 544 |
|
| 545 |
//! |
| 546 |
//! \brief Unregister RT surfaces |
| 547 |
//! |
| 548 |
//! \param [in] ctx |
| 549 |
//! Pointer to VA driver context |
| 550 |
//! \param [in] surface |
| 551 |
//! Pointer to ddi media surface |
| 552 |
//! |
| 553 |
//! \return VAStatus |
| 554 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 555 |
//! |
| 556 |
static VAStatus UnRegisterRTSurfaces(VADriverContextP ctx, PDDI_MEDIA_SURFACE surface); |
| 557 |
|
| 558 |
//! |
| 559 |
//! \brief Free surface |
| 560 |
//! |
| 561 |
//! \param [in] surface |
| 562 |
//! Ddi media surface |
| 563 |
//! |
| 564 |
static void FreeSurface(DDI_MEDIA_SURFACE *surface); |
| 565 |
|
| 566 |
//! |
| 567 |
//! \brief Free buffer |
| 568 |
//! |
| 569 |
//! \param [in] buf |
| 570 |
//! Ddi media buffer |
| 571 |
//! |
| 572 |
static void FreeBuffer(DDI_MEDIA_BUFFER *buf); |
| 573 |
|
| 574 |
//! |
| 575 |
//! \brief Lock surface |
| 576 |
//! |
| 577 |
//! \param [in] surface |
| 578 |
//! Ddi media surface |
| 579 |
//! \param [in] flag |
| 580 |
//! Flag |
| 581 |
//! |
| 582 |
//! \return void* |
| 583 |
//! Pointer to lock surface data |
| 584 |
//! |
| 585 |
static void* LockSurface(DDI_MEDIA_SURFACE *surface, uint32_t flag); |
| 586 |
|
| 587 |
//! |
| 588 |
//! \brief Lock surface |
| 589 |
//! |
| 590 |
//! \param [in] surface |
| 591 |
//! Ddi media surface |
| 592 |
//! \param [in] flag |
| 593 |
//! Flag |
| 594 |
//! |
| 595 |
//! \return void* |
| 596 |
//! Pointer to lock surface data |
| 597 |
//! |
| 598 |
static void* LockSurfaceInternal(DDI_MEDIA_SURFACE *surface, uint32_t flag); |
| 599 |
|
| 600 |
//! |
| 601 |
//! \brief Create Shadow Resource of Ddi media surface |
| 602 |
//! |
| 603 |
//! \param [in] surface |
| 604 |
//! Ddi media surface |
| 605 |
//! |
| 606 |
//! \return VAStatus |
| 607 |
//! |
| 608 |
static VAStatus CreateShadowResource(DDI_MEDIA_SURFACE *surface); |
| 609 |
|
| 610 |
//! |
| 611 |
//! \brief Unlock surface |
| 612 |
//! |
| 613 |
//! \param [in] surface |
| 614 |
//! Ddi media surface |
| 615 |
//! |
| 616 |
static void UnlockSurface(DDI_MEDIA_SURFACE *surface); |
| 617 |
|
| 618 |
//! |
| 619 |
//! \brief Lock buffer |
| 620 |
//! |
| 621 |
//! \param [in] buf |
| 622 |
//! Ddi media buffer |
| 623 |
//! \param [in] flag |
| 624 |
//! Flag |
| 625 |
//! |
| 626 |
//! \return void* |
| 627 |
//! Pointer to lock buffer data |
| 628 |
//! |
| 629 |
static void* LockBuffer(DDI_MEDIA_BUFFER *buf, uint32_t flag); |
| 630 |
|
| 631 |
//! |
| 632 |
//! \brief Unlock buffer |
| 633 |
//! |
| 634 |
//! \param [in] buf |
| 635 |
//! Ddi media buffer |
| 636 |
//! |
| 637 |
static void UnlockBuffer(DDI_MEDIA_BUFFER *buf); |
| 638 |
|
| 639 |
//! |
| 640 |
//! \brief Swizzle Surface |
| 641 |
//! |
| 642 |
//! \param [in] mediaCtx |
| 643 |
//! Pointer to VA driver context |
| 644 |
//! \param [in] pGmmResInfo |
| 645 |
//! Gmm resource info |
| 646 |
//! \param [in] pLockedAddr |
| 647 |
//! Pointer to locked address |
| 648 |
//! \param [in] TileType |
| 649 |
//! Tile type |
| 650 |
//! \param [in] pResourceBase |
| 651 |
//! Pointer to resource base |
| 652 |
//! \param [in] bUpload |
| 653 |
//! Blt upload |
| 654 |
//! \return VAStatus |
| 655 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 656 |
//! |
| 657 |
static VAStatus SwizzleSurface( |
| 658 |
PDDI_MEDIA_CONTEXT mediaCtx, |
| 659 |
PGMM_RESOURCE_INFO pGmmResInfo, |
| 660 |
void *pLockedAddr, |
| 661 |
uint32_t TileType, |
| 662 |
uint8_t *pResourceBase, |
| 663 |
bool bUpload); |
| 664 |
|
| 665 |
//! |
| 666 |
//! \brief Create buffer |
| 667 |
//! |
| 668 |
//! \param [out] buffer |
| 669 |
//! Ddi media buffer |
| 670 |
//! \param [in] bufmgr |
| 671 |
//! Mos buffer manager |
| 672 |
//! |
| 673 |
//! \return VAStatus |
| 674 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 675 |
//! |
| 676 |
static VAStatus CreateBuffer( |
| 677 |
DDI_MEDIA_BUFFER *buffer, |
| 678 |
MOS_BUFMGR *bufmgr); |
| 679 |
|
| 680 |
//! |
| 681 |
//! \brief Allocate pmedia buffer from heap |
| 682 |
//! |
| 683 |
//! \param [in] bufferHeap |
| 684 |
//! Pointer to ddi media heap |
| 685 |
//! |
| 686 |
//! \return PDDI_MEDIA_BUFFER_HEAP_ELEMENT |
| 687 |
//! Pointer to ddi media buffer heap element |
| 688 |
//! |
| 689 |
static PDDI_MEDIA_BUFFER_HEAP_ELEMENT AllocPMediaBufferFromHeap(PDDI_MEDIA_HEAP bufferHeap); |
| 690 |
|
| 691 |
//! |
| 692 |
//! \brief Allocate PVA image from heap |
| 693 |
//! |
| 694 |
//! \param [in] imageHeap |
| 695 |
//! Pointer to ddi media heap |
| 696 |
//! |
| 697 |
//! \return PDDI_MEDIA_IMAGE_HEAP_ELEMENT |
| 698 |
//! Pointer to ddi media image heap element |
| 699 |
//! |
| 700 |
static PDDI_MEDIA_IMAGE_HEAP_ELEMENT AllocPVAImageFromHeap(PDDI_MEDIA_HEAP imageHeap); |
| 701 |
|
| 702 |
//! |
| 703 |
//! \brief convert FOURCC to Gmm Format. |
| 704 |
//! |
| 705 |
//! \param [in] fourcc |
| 706 |
//! |
| 707 |
//! \return GMM_RESOURCE_FORMAT |
| 708 |
//! Pointer to gmm format type |
| 709 |
//! |
| 710 |
static GMM_RESOURCE_FORMAT ConvertFourccToGmmFmt(uint32_t fourcc); |
| 711 |
|
| 712 |
//! \brief Get surface drm modifier |
| 713 |
//! |
| 714 |
//! \param [in] mediaCtx |
| 715 |
//! Media context |
| 716 |
//! \param [in] mediaSurface |
| 717 |
//! Pointer to the media surface |
| 718 |
//! \param [out] modifier |
| 719 |
//! Reference of the modifier |
| 720 |
//! |
| 721 |
//! \return VAStatus |
| 722 |
//! VA_STATUS_SUCCESS if success |
| 723 |
//! |
| 724 |
static VAStatus GetSurfaceModifier( |
| 725 |
DDI_MEDIA_CONTEXT *mediaCtx, |
| 726 |
DDI_MEDIA_SURFACE *mediaSurface, |
| 727 |
uint64_t &modifier); |
| 728 |
|
| 729 |
//! |
| 730 |
//! \brief Release pmedia buffer from heap |
| 731 |
//! |
| 732 |
//! \param [in] bufferHeap |
| 733 |
//! Pointer to ddi media heap |
| 734 |
//! \param [in] vaBufferID |
| 735 |
//! VA buffer ID |
| 736 |
//! |
| 737 |
static void ReleasePMediaBufferFromHeap( |
| 738 |
PDDI_MEDIA_HEAP bufferHeap, |
| 739 |
uint32_t vaBufferID); |
| 740 |
|
| 741 |
//! |
| 742 |
//! \brief Init a mutex |
| 743 |
//! |
| 744 |
//! \param [in] mutex |
| 745 |
//! input mutex |
| 746 |
//! \return void |
| 747 |
//! |
| 748 |
static void InitMutex(PMEDIA_MUTEX_T mutex); |
| 749 |
|
| 750 |
//! |
| 751 |
//! \brief Dstroy a mutex |
| 752 |
//! |
| 753 |
//! \param [in] mutex |
| 754 |
//! input mutex |
| 755 |
//! \return void |
| 756 |
//! |
| 757 |
static void DestroyMutex(PMEDIA_MUTEX_T mutex); |
| 758 |
|
| 759 |
//! |
| 760 |
//! \brief Set media reset enable flag |
| 761 |
//! |
| 762 |
//! \param [in] mediaCtx |
| 763 |
//! Pointer to VA driver context |
| 764 |
//! \return VAStatus |
| 765 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 766 |
//! |
| 767 |
static VAStatus SetMediaResetEnableFlag(PDDI_MEDIA_CONTEXT mediaCtx); |
| 768 |
|
| 769 |
//! |
| 770 |
//! \brief Allocate PVA context from heap |
| 771 |
//! |
| 772 |
//! \param [in] vaContextHeap |
| 773 |
//! Pointer to ddi media heap |
| 774 |
//! |
| 775 |
//! \return PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT |
| 776 |
//! Pointer to ddi media vacontext heap element |
| 777 |
//! |
| 778 |
static PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT DdiAllocPVAContextFromHeap(PDDI_MEDIA_HEAP vaContextHeap); |
| 779 |
|
| 780 |
//! |
| 781 |
//! \brief Release PVA context from heap |
| 782 |
//! |
| 783 |
//! \param [in] vaContextHeap |
| 784 |
//! Pointer to ddi media heap |
| 785 |
//! \param [in] vaContextID |
| 786 |
//! VA context ID |
| 787 |
//! |
| 788 |
static void DdiReleasePVAContextFromHeap(PDDI_MEDIA_HEAP vaContextHeap, uint32_t vaContextID); |
| 789 |
|
| 790 |
//! |
| 791 |
//! \brief map from media format to vphal format |
| 792 |
//! |
| 793 |
//! \params [in] mediaFormat |
| 794 |
//! DDI_MEDIA_FORMAT |
| 795 |
//! |
| 796 |
//! \returns MOS_FORMAT |
| 797 |
//! |
| 798 |
static MOS_FORMAT GetFormatFromMediaFormat(DDI_MEDIA_FORMAT mediaFormat); |
| 799 |
|
| 800 |
//! \brief Get the VP Tile Type from Media Tile Type. |
| 801 |
//! |
| 802 |
//! \params [in] mediaTileType |
| 803 |
//! input mediaTileType |
| 804 |
//! |
| 805 |
//! \returns Vp tile Type if call succeeds |
| 806 |
//! |
| 807 |
static MOS_TILE_TYPE GetTileTypeFromMediaTileType(uint32_t mediaTileType); |
| 808 |
|
| 809 |
//! |
| 810 |
//! \brief Get ColorSpace from the media format |
| 811 |
//! |
| 812 |
//! \params [in] format |
| 813 |
//! media format |
| 814 |
//! |
| 815 |
//! \returns appropriate VPHAL_CSPACE if call succeeds, CSpace_None otherwise |
| 816 |
//! |
| 817 |
static VPHAL_CSPACE GetColorSpaceFromMediaFormat(DDI_MEDIA_FORMAT format); |
| 818 |
|
| 819 |
//! |
| 820 |
//! \brief Unreference buf object media buffer |
| 821 |
//! |
| 822 |
//! \param [in] buf |
| 823 |
//! Pointer to ddi media buffer |
| 824 |
//! |
| 825 |
static void UnRefBufObjInMediaBuffer(PDDI_MEDIA_BUFFER buf); |
| 826 |
|
| 827 |
//! |
| 828 |
//! \brief ReleaseP VAImage From Heap |
| 829 |
//! |
| 830 |
//! \param [in] imageHeap |
| 831 |
//! Image heap |
| 832 |
//! \param [in] vaImageID |
| 833 |
//! VA image ID |
| 834 |
//! |
| 835 |
static void ReleasePVAImageFromHeap(PDDI_MEDIA_HEAP imageHeap, uint32_t vaImageID); |
| 836 |
|
| 837 |
//! |
| 838 |
//! \brief Media print frame per second |
| 839 |
//! |
| 840 |
static void MediaPrintFps(); |
| 841 |
private: |
| 842 |
static int32_t m_frameCountFps; |
| 843 |
static struct timeval m_tv1; |
| 844 |
static pthread_mutex_t m_fpsMutex; |
| 845 |
static int32_t m_vaFpsSampleSize; |
| 846 |
static bool m_isMediaFpsPrintFpsEnabled; |
| 847 |
MEDIA_CLASS_DEFINE_END(MediaLibvaUtilNext) |
| 848 |
}; |
| 849 |
|
| 850 |
//! |
| 851 |
//! \brief Helper inline class intended to simplify mutex lock/unlock |
| 852 |
//! operations primarily used as a stack-allocated object. |
| 853 |
//! In that case, the compiler guarantees to call the destructor |
| 854 |
//! leaving the scope. The class becomes handy in functions |
| 855 |
//! where there are several return statements with different |
| 856 |
//! exit code value. |
| 857 |
//! |
| 858 |
class MediaLibvaUtilNext_LockGuard { |
| 859 |
private: |
| 860 |
PMEDIA_MUTEX_T m_pMutex; |
| 861 |
public: |
| 862 |
MediaLibvaUtilNext_LockGuard(PMEDIA_MUTEX_T pMutex):m_pMutex(pMutex) |
| 863 |
{ |
| 864 |
MosUtilities::MosLockMutex(m_pMutex); |
| 865 |
} |
| 866 |
~MediaLibvaUtilNext_LockGuard() |
| 867 |
{ |
| 868 |
MosUtilities::MosUnlockMutex(m_pMutex); |
| 869 |
} |
| 870 |
MEDIA_CLASS_DEFINE_END(MediaLibvaUtilNext_LockGuard) |
| 871 |
}; |
| 872 |
|
| 873 |
#endif //__MEDIA_LIBVA_UTIL_NEXT_H__ |