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
|
/*
* Copyright (c) 2009-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_libva_util.h
//! \brief libva(and its extension) utility head file
//!
#ifndef __MEDIA_LIBVA_UTIL_H__
#define __MEDIA_LIBVA_UTIL_H__
#include "media_libva_common.h"
#include "mos_util_debug.h"
#include "mos_bufmgr.h"
#define DEVICE_NAME "/dev/dri/renderD128" // For Gen, it is always /dev/dri/renderD128 node
//!
//! \brief Media print frame per second
//!
void DdiMediaUtil_MediaPrintFps();
//!
//! \brief Create surface
//!
//! \param [in] surface
//! Ddi media surface
//! \param [in] mediaDrvCtx
//! Pointer to ddi media context
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if success, else fail reason
//!
VAStatus DdiMediaUtil_CreateSurface(DDI_MEDIA_SURFACE *surface, PDDI_MEDIA_CONTEXT mediaDrvCtx);
//!
//! \brief Create buffer
//!
//! \param [out] buffer
//! Ddi media buffer
//! \param [in] bufmgr
//! Mos buffer manager
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if success, else fail reason
//!
VAStatus DdiMediaUtil_CreateBuffer(DDI_MEDIA_BUFFER *buffer, mos_bufmgr *bufmgr);
//!
//! \brief Lock surface
//!
//! \param [in] surface
//! Ddi media surface
//! \param [in] flag
//! Flag
//!
//! \return void*
//! Pointer to lock surface data
//!
void* DdiMediaUtil_LockSurface(DDI_MEDIA_SURFACE *surface, uint32_t flag);
//!
//! \brief Unlock surface
//!
//! \param [in] surface
//! Ddi media surface
//!
void DdiMediaUtil_UnlockSurface(DDI_MEDIA_SURFACE *surface);
//!
//! \brief Lock buffer
//!
//! \param [in] buf
//! Ddi media buffer
//! \param [in] flag
//! Flag
//!
//! \return void*
//! Pointer to lock buffer data
//!
void* DdiMediaUtil_LockBuffer(DDI_MEDIA_BUFFER *buf, uint32_t flag);
//!
//! \brief Unlock buffer
//!
//! \param [in] buf
//! Ddi media buffer
//!
void DdiMediaUtil_UnlockBuffer(DDI_MEDIA_BUFFER *buf);
//!
//! \brief Free surface
//!
//! \param [in] surface
//! Ddi media surface
//!
void DdiMediaUtil_FreeSurface(DDI_MEDIA_SURFACE *surface);
//!
//! \brief Free buffer
//!
//! \param [in] buf
//! Ddi media buffer
//!
void DdiMediaUtil_FreeBuffer(DDI_MEDIA_BUFFER *buf);
//!
//! \brief Init mutex
//!
//! \param [in] mutex
//! Pointer to media mutex thread
//!
void DdiMediaUtil_InitMutex(PMEDIA_MUTEX_T mutex);
//!
//! \brief Destroy mutex
//!
//! \param [in] mutex
//! Pointer to media mutex thread
//!
void DdiMediaUtil_DestroyMutex(PMEDIA_MUTEX_T mutex);
//!
//! \brief Lock mutex
//!
//! \param [in] mutex
//! Pointer to media mutex thread
//!
void DdiMediaUtil_LockMutex(PMEDIA_MUTEX_T mutex);
//!
//! \brief Unlock mutex
//!
//! \param [in] mutex
//! Pointer to media mutex thread
//!
void DdiMediaUtil_UnLockMutex(PMEDIA_MUTEX_T mutex);
//!
//! \brief Helper inline class intended to simplify mutex lock/unlock
//! operations primarily used as a stack-allocated object.
//! In that case, the compiler guarantees to call the destructor
//! leaving the scope. The class becomes handy in functions
//! where there are several return statements with different
//! exit code value.
//!
class DdiMediaUtil_LockGuard {
private:
PMEDIA_MUTEX_T m_pMutex;
public:
DdiMediaUtil_LockGuard(PMEDIA_MUTEX_T pMutex):m_pMutex(pMutex)
{
DdiMediaUtil_LockMutex(m_pMutex);
}
~DdiMediaUtil_LockGuard()
{
DdiMediaUtil_UnLockMutex(m_pMutex);
}
};
//!
//! \brief Destroy semaphore
//!
//! \param [in] sem
//! Pointer to media semaphore thread
//!
void DdiMediaUtil_DestroySemaphore(PMEDIA_SEM_T sem);
//!
//! \brief Wait semaphore
//!
//! \param [in] sem
//! Pointer to media semaphore thread
//!
void DdiMediaUtil_WaitSemaphore(PMEDIA_SEM_T sem);
//!
//! \brief Try wait semaphore
//!
//! \param [in] sem
//! Pointer to media semaphore thread
//!
//! \return int32_t
//! Try wait for semaphore. Return 0 if success, else -1 if fail
//!
int32_t DdiMediaUtil_TryWaitSemaphore(PMEDIA_SEM_T sem);
//!
//! \brief Post semaphore
//!
//! \param [in] sem
//! Pointer to media semaphore thread
//!
void DdiMediaUtil_PostSemaphore(PMEDIA_SEM_T sem);
//!
//! \brief Fill a rect structure with the regsion specified by parameters
//!
//! \param [in] rect
//! Input pointer to the rect
//! \param [in] offset_x
//! X offset of the region
//! \param [in] offset_y
//! Y offset of the region
//! \param [in] width
//! Width of the region
//! \param [in] height
//! Height of the region
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if success, else fail reason
//!
VAStatus DdiMediaUtil_FillPositionToRect(RECT *rect, int16_t offset_x, int16_t offset_y, int16_t width, int16_t height);
//!
//! \brief Is external surface
//! \details If the bo of media surface was allocated from App,
//! should return true, otherwise, false. In current implemeation
//! external buffer passed with pSurfDesc.
//!
//! \param [in] surface
//! Pointer to ddi media surface
//!
//! \return bool
//! true if surface is external, else false
//!
bool DdiMediaUtil_IsExternalSurface(PDDI_MEDIA_SURFACE surface);
//!
//! \brief Allocate pmedia surface from heap
//!
//! \param [in] surfaceHeap
//! Pointer to ddi media heap
//!
//! \return PDDI_MEDIA_SURFACE_HEAP_ELEMENT
//! Pointer to ddi media surface heap element
//!
PDDI_MEDIA_SURFACE_HEAP_ELEMENT DdiMediaUtil_AllocPMediaSurfaceFromHeap(PDDI_MEDIA_HEAP surfaceHeap);
//!
//! \brief Release pmedia surface from heap
//!
//! \param [in] surfaceHeap
//! Pointer to ddi media heap
//! \param [in] vaSurfaceID
//! VA surface ID
//!
void DdiMediaUtil_ReleasePMediaSurfaceFromHeap(PDDI_MEDIA_HEAP surfaceHeap, uint32_t vaSurfaceID);
//!
//! \brief Allocate pmedia buffer from heap
//!
//! \param [in] bufferHeap
//! Pointer to ddi media heap
//!
//! \return PDDI_MEDIA_BUFFER_HEAP_ELEMENT
//! Pointer to ddi media buffer heap element
//!
PDDI_MEDIA_BUFFER_HEAP_ELEMENT DdiMediaUtil_AllocPMediaBufferFromHeap(PDDI_MEDIA_HEAP bufferHeap);
//!
//! \brief Release pmedia buffer from heap
//!
//! \param [in] bufferHeap
//! Pointer to ddi media heap
//! \param [in] vaBufferID
//! VA buffer ID
//!
void DdiMediaUtil_ReleasePMediaBufferFromHeap(PDDI_MEDIA_HEAP bufferHeap, uint32_t vaBufferID);
//!
//! \brief Allocate PVA image from heap
//!
//! \param [in] imageHeap
//! Pointer to ddi media heap
//!
//! \return PDDI_MEDIA_IMAGE_HEAP_ELEMENT
//! Pointer to ddi media image heap element
//!
PDDI_MEDIA_IMAGE_HEAP_ELEMENT DdiMediaUtil_AllocPVAImageFromHeap(PDDI_MEDIA_HEAP imageHeap);
//!
//! \brief Release PVA image from heap
//!
//! \param [in] imageHeap
//! Pointer to ddi media heap
//! \param [in] vaImageID
//! VA image ID
//!
void DdiMediaUtil_ReleasePVAImageFromHeap(PDDI_MEDIA_HEAP imageHeap, uint32_t vaImageID);
//!
//! \brief Allocate PVA context from heap
//!
//! \param [in] vaContextHeap
//! Pointer to ddi media heap
//!
//! \return PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT
//! Pointer to ddi media vacontext heap element
//!
PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT DdiMediaUtil_AllocPVAContextFromHeap(PDDI_MEDIA_HEAP vaContextHeap);
//!
//! \brief Release PVA context from heap
//!
//! \param [in] vaContextHeap
//! Pointer to ddi media heap
//! \param [in] vaContextID
//! VA context ID
//!
void DdiMediaUtil_ReleasePVAContextFromHeap(PDDI_MEDIA_HEAP vaContextHeap, uint32_t vaContextID);
//!
//! \brief Unreference buf object media buffer
//!
//! \param [in] buf
//! Pointer to ddi media buffer
//!
void DdiMediaUtil_UnRefBufObjInMediaBuffer(PDDI_MEDIA_BUFFER buf);
//!
//! \brief Open Intel's Graphics Device to get the file descriptor
//!
//! \param [in] devName
//! Device name
//!
//! \return int32_t
//! Device name header. Return 0 if success, else -1 if fail.
//!
int32_t DdiMediaUtil_OpenGraphicsAdaptor(char *devName);
//!
//! \brief Unregister RT surfaces
//!
//! \param [in] ctx
//! Pointer to VA driver context
//! \param [in] surface
//! Pointer to ddi media surface
//!
//! \return VAStatus
//! VA_STATUS_SUCCESS if success, else fail reason
//!
VAStatus DdiMediaUtil_UnRegisterRTSurfaces(VADriverContextP ctx,PDDI_MEDIA_SURFACE surface);
//------------------------------------------------------------------------------
// Macros for debug messages, Assert, Null check and condition check within ddi files
//------------------------------------------------------------------------------
#define DDI_ASSERT(_expr) \
MOS_ASSERT(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF, _expr)
#define DDI_ASSERTMESSAGE(_message, ...) \
MOS_ASSERTMESSAGE(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF, _message, ##__VA_ARGS__)
#define DDI_NORMALMESSAGE(_message, ...) \
MOS_NORMALMESSAGE(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF, _message, ##__VA_ARGS__)
#define DDI_VERBOSEMESSAGE(_message, ...) \
MOS_VERBOSEMESSAGE(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF, _message, ##__VA_ARGS__)
#ifdef ANDROID
#define DDI_FUNCTION_ENTER() UMD_ATRACE_BEGIN(__FUNCTION__)
#define DDI_FUNCTION_EXIT(status) UMD_ATRACE_END
#else
#define DDI_FUNCTION_ENTER() \
MOS_FUNCTION_ENTER(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF)
#define DDI_FUNCTION_EXIT(status) \
MOS_FUNCTION_EXIT(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF, status)
#endif
// If pointer is nullptr, print the error message and return the specified value.
#define DDI_CHK_NULL(_ptr, _str, _ret) \
DDI_CHK_CONDITION((nullptr == (_ptr)), _str, _ret)
#define DDI_CHK_LARGER(p, bottom, str, ret) \
DDI_CHK_CONDITION((p <= bottom),str,ret)
#define DDI_CHK_LESS(p, upper, str, ret) \
DDI_CHK_CONDITION((p >= upper),str,ret)
// Check the return value of function.
// If failed, print the error message and return,
// do nothing otherwise.
#define DDI_CHK_RET(_ret, _str) \
{ \
VAStatus tmpRet = _ret; \
if (VA_STATUS_SUCCESS != tmpRet) { \
DDI_ASSERTMESSAGE("%s [%d].", _str, tmpRet); \
return tmpRet; \
} \
}
// Check the return status of parse function in renderPicture
// If failed, assign new status and break
// do nothing otherwise.
#define DDI_CHK_STATUS(_ret, _newret) \
{ \
if (VA_STATUS_SUCCESS != _ret) { \
vaStatus = _newret; \
break; \
} \
}
// Check the condition, if true, print the error message
// and return the specified value, do nothing otherwise.
#define DDI_CHK_CONDITION(condition, _str, _ret) \
if (condition) { \
DDI_ASSERTMESSAGE(_str); \
return _ret; \
}
#define DDI_CHK_STATUS_MESSAGE(_ptr, _message, ...) \
MOS_CHK_STATUS_MESSAGE(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF, _ptr, _message, ##__VA_ARGS__)
#define DDI_CHK_HR_MESSAGE(_ptr, _message, ...) \
MOS_CHK_HR_MESSAGE(MOS_COMPONENT_DDI, MOS_DDI_SUBCOMP_SELF, _ptr, _message, ##__VA_ARGS__)
#ifdef ANDROID
// Enable new specification for video formats
// \see memo "Color format Usage on Android"
#ifndef UFO_GRALLOC_NEW_FORMAT
#define UFO_GRALLOC_NEW_FORMAT 1
#endif
#endif
#endif
|