| 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_common_next.cpp |
| 24 |
//! \brief libva common next implementaion. |
| 25 |
//! |
| 26 |
#include <stdint.h> |
| 27 |
#include "mos_utilities.h" |
| 28 |
#include "media_libva_common_next.h" |
| 29 |
#include "media_libva_util_next.h" |
| 30 |
#include "mos_solo_generic.h" |
| 31 |
#include "mos_interface.h" |
| 32 |
#include "media_libva_interface_next.h" |
| 33 |
#include "media_ddi_prot.h" |
| 34 |
|
| 35 |
DDI_MEDIA_SURFACE* MediaLibvaCommonNext::GetSurfaceFromVASurfaceID(PDDI_MEDIA_CONTEXT mediaCtx, VASurfaceID surfaceID) |
| 36 |
{ |
| 37 |
uint32_t id = 0; |
| 38 |
PDDI_MEDIA_SURFACE_HEAP_ELEMENT surfaceElement = nullptr; |
| 39 |
PDDI_MEDIA_SURFACE surface = nullptr; |
| 40 |
DDI_FUNC_ENTER; |
| 41 |
DDI_CHK_NULL(mediaCtx, "nullptr mediaCtx", nullptr); |
| 42 |
|
| 43 |
id = (uint32_t)surfaceID; |
| 44 |
bool validSurface = (id != VA_INVALID_SURFACE); |
| 45 |
if(validSurface) |
| 46 |
{ |
| 47 |
DDI_CHK_LESS(id, mediaCtx->pSurfaceHeap->uiAllocatedHeapElements, "invalid surface id", nullptr); |
| 48 |
MosUtilities::MosLockMutex(&mediaCtx->SurfaceMutex); |
| 49 |
surfaceElement = (PDDI_MEDIA_SURFACE_HEAP_ELEMENT)mediaCtx->pSurfaceHeap->pHeapBase; |
| 50 |
surfaceElement += id; |
| 51 |
surface = surfaceElement->pSurface; |
| 52 |
MosUtilities::MosUnlockMutex(&mediaCtx->SurfaceMutex); |
| 53 |
} |
| 54 |
|
| 55 |
return surface; |
| 56 |
} |
| 57 |
|
| 58 |
void MediaLibvaCommonNext::MediaSurfaceToMosResource(DDI_MEDIA_SURFACE *mediaSurface, MOS_RESOURCE *mosResource) |
| 59 |
{ |
| 60 |
DDI_FUNC_ENTER; |
| 61 |
DDI_CHK_NULL(mediaSurface, "nullptr mediaSurface",); |
| 62 |
DDI_CHK_NULL(mosResource, "nullptr mosResource",); |
| 63 |
|
| 64 |
MosInterface::ConvertResourceFromDdi(mediaSurface, mosResource, OS_SPECIFIC_RESOURCE_SURFACE, 0); |
| 65 |
|
| 66 |
Mos_Solo_SetOsResource(mediaSurface->pGmmResourceInfo, mosResource); |
| 67 |
|
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
void MediaLibvaCommonNext::MediaBufferToMosResource(DDI_MEDIA_BUFFER *mediaBuffer, MOS_RESOURCE *mosResource) |
| 72 |
{ |
| 73 |
DDI_FUNC_ENTER; |
| 74 |
DDI_CHK_NULL(mediaBuffer, "nullptr mediaBuffer",); |
| 75 |
DDI_CHK_NULL(mosResource, "nullptr mosResource",); |
| 76 |
|
| 77 |
if (nullptr == mediaBuffer->bo) |
| 78 |
{ |
| 79 |
DDI_ASSERTMESSAGE("nullptr mediaBuffer->bo"); |
| 80 |
} |
| 81 |
|
| 82 |
MosInterface::ConvertResourceFromDdi(mediaBuffer, mosResource, OS_SPECIFIC_RESOURCE_BUFFER, 0); |
| 83 |
|
| 84 |
Mos_Solo_SetOsResource(mediaBuffer->pGmmResourceInfo, mosResource); |
| 85 |
|
| 86 |
return; |
| 87 |
} |
| 88 |
|
| 89 |
VASurfaceID MediaLibvaCommonNext::GetVASurfaceIDFromSurface(PDDI_MEDIA_SURFACE surface) |
| 90 |
{ |
| 91 |
DDI_FUNC_ENTER; |
| 92 |
DDI_CHK_NULL(surface, "nullptr surface", VA_INVALID_SURFACE); |
| 93 |
DDI_CHK_NULL(surface->pMediaCtx, "nullptr mediaCtx", VA_INVALID_SURFACE); |
| 94 |
DDI_CHK_NULL(surface->pMediaCtx->pSurfaceHeap, "nullptr surface heap", VA_INVALID_SURFACE); |
| 95 |
|
| 96 |
PDDI_MEDIA_SURFACE_HEAP_ELEMENT surfaceElement = (PDDI_MEDIA_SURFACE_HEAP_ELEMENT)surface->pMediaCtx->pSurfaceHeap->pHeapBase; |
| 97 |
DDI_CHK_NULL(surfaceElement, "nullptr surface element", VA_INVALID_SURFACE); |
| 98 |
for(uint32_t i = 0; i < surface->pMediaCtx->pSurfaceHeap->uiAllocatedHeapElements; i ++) |
| 99 |
{ |
| 100 |
if(surface == surfaceElement->pSurface) |
| 101 |
{ |
| 102 |
return surfaceElement->uiVaSurfaceID; |
| 103 |
} |
| 104 |
surfaceElement ++; |
| 105 |
} |
| 106 |
return VA_INVALID_SURFACE; |
| 107 |
} |
| 108 |
|
| 109 |
PDDI_MEDIA_SURFACE MediaLibvaCommonNext::ReplaceSurfaceWithNewFormat(PDDI_MEDIA_SURFACE surface, DDI_MEDIA_FORMAT expectedFormat) |
| 110 |
{ |
| 111 |
DDI_FUNC_ENTER; |
| 112 |
DDI_CHK_NULL(surface, "nullptr surface", nullptr); |
| 113 |
|
| 114 |
PDDI_MEDIA_SURFACE_HEAP_ELEMENT surfaceElement = (PDDI_MEDIA_SURFACE_HEAP_ELEMENT)surface->pMediaCtx->pSurfaceHeap->pHeapBase; |
| 115 |
PDDI_MEDIA_CONTEXT mediaCtx = surface->pMediaCtx; |
| 116 |
|
| 117 |
// Check some conditions |
| 118 |
if (expectedFormat == surface->format) |
| 119 |
{ |
| 120 |
return surface; |
| 121 |
} |
| 122 |
// Create new dst surface and copy the structure |
| 123 |
PDDI_MEDIA_SURFACE dstSurface = (DDI_MEDIA_SURFACE *)MOS_AllocAndZeroMemory(sizeof(DDI_MEDIA_SURFACE)); |
| 124 |
if (nullptr == surfaceElement) |
| 125 |
{ |
| 126 |
MOS_FreeMemory(dstSurface); |
| 127 |
return nullptr; |
| 128 |
} |
| 129 |
|
| 130 |
MOS_SecureMemcpy(dstSurface, sizeof(DDI_MEDIA_SURFACE), surface, sizeof(DDI_MEDIA_SURFACE)); |
| 131 |
DDI_CHK_NULL(dstSurface, "nullptr dstSurface", nullptr); |
| 132 |
dstSurface->format = expectedFormat; |
| 133 |
dstSurface->uiLockedBufID = VA_INVALID_ID; |
| 134 |
dstSurface->uiLockedImageID = VA_INVALID_ID; |
| 135 |
dstSurface->pSurfDesc = nullptr; |
| 136 |
// Lock surface heap |
| 137 |
MosUtilities::MosLockMutex(&mediaCtx->SurfaceMutex); |
| 138 |
uint32_t i; |
| 139 |
// Get current element heap and index |
| 140 |
for (i = 0; i < mediaCtx->pSurfaceHeap->uiAllocatedHeapElements; i++) |
| 141 |
{ |
| 142 |
if (surface == surfaceElement->pSurface) |
| 143 |
{ |
| 144 |
break; |
| 145 |
} |
| 146 |
surfaceElement++; |
| 147 |
} |
| 148 |
// If cant find |
| 149 |
if (i == surface->pMediaCtx->pSurfaceHeap->uiAllocatedHeapElements) |
| 150 |
{ |
| 151 |
MosUtilities::MosUnlockMutex(&mediaCtx->SurfaceMutex); |
| 152 |
MOS_FreeMemory(dstSurface); |
| 153 |
return nullptr; |
| 154 |
} |
| 155 |
// FreeSurface |
| 156 |
MediaLibvaUtilNext::FreeSurface(surface); |
| 157 |
MOS_FreeMemory(surface); |
| 158 |
// CreateNewSurface |
| 159 |
MediaLibvaUtilNext::CreateSurface(dstSurface,mediaCtx); |
| 160 |
surfaceElement->pSurface = dstSurface; |
| 161 |
|
| 162 |
MosUtilities::MosUnlockMutex(&mediaCtx->SurfaceMutex); |
| 163 |
|
| 164 |
return dstSurface; |
| 165 |
} |
| 166 |
|
| 167 |
PDDI_MEDIA_SURFACE MediaLibvaCommonNext::ReplaceSurfaceWithVariant(PDDI_MEDIA_SURFACE surface, VAEntrypoint entrypoint) |
| 168 |
{ |
| 169 |
DDI_FUNC_ENTER; |
| 170 |
DDI_CHK_NULL(surface, "nullptr surface", nullptr); |
| 171 |
|
| 172 |
PDDI_MEDIA_CONTEXT mediaCtx = surface->pMediaCtx; |
| 173 |
DDI_CHK_NULL(mediaCtx, "nullptr mediaCtx", nullptr); |
| 174 |
uint32_t alignedWidth, alignedHeight; |
| 175 |
DDI_MEDIA_FORMAT alignedFormat; |
| 176 |
|
| 177 |
if(surface->uiVariantFlag) |
| 178 |
{ |
| 179 |
return surface; |
| 180 |
} |
| 181 |
|
| 182 |
VASurfaceID vaID = MediaLibvaCommonNext::GetVASurfaceIDFromSurface(surface); |
| 183 |
if(VA_INVALID_SURFACE == vaID) |
| 184 |
{ |
| 185 |
return nullptr; |
| 186 |
} |
| 187 |
|
| 188 |
MosUtilities::MosLockMutex(&mediaCtx->SurfaceMutex); |
| 189 |
PDDI_MEDIA_SURFACE_HEAP_ELEMENT surfaceElement = (PDDI_MEDIA_SURFACE_HEAP_ELEMENT)surface->pMediaCtx->pSurfaceHeap->pHeapBase; |
| 190 |
if (surfaceElement == nullptr) |
| 191 |
{ |
| 192 |
MosUtilities::MosUnlockMutex(&mediaCtx->SurfaceMutex); |
| 193 |
return nullptr; |
| 194 |
} |
| 195 |
surfaceElement += vaID; |
| 196 |
MosUtilities::MosUnlockMutex(&mediaCtx->SurfaceMutex); |
| 197 |
|
| 198 |
alignedFormat = surface->format; |
| 199 |
switch (surface->format) |
| 200 |
{ |
| 201 |
case Media_Format_AYUV: |
| 202 |
#if VA_CHECK_VERSION(1, 13, 0) |
| 203 |
case Media_Format_XYUV: |
| 204 |
#endif |
| 205 |
alignedWidth = MOS_ALIGN_CEIL(surface->iWidth, 128); |
| 206 |
alignedHeight = MOS_ALIGN_CEIL(surface->iHeight * 3 / 4, 64); |
| 207 |
break; |
| 208 |
case Media_Format_Y410: |
| 209 |
alignedWidth = MOS_ALIGN_CEIL(surface->iWidth, 64); |
| 210 |
alignedHeight = MOS_ALIGN_CEIL(surface->iHeight * 3 / 2, 64); |
| 211 |
break; |
| 212 |
case Media_Format_Y216: |
| 213 |
#if VA_CHECK_VERSION(1, 9, 0) |
| 214 |
case Media_Format_Y212: |
| 215 |
#endif |
| 216 |
case Media_Format_Y210: |
| 217 |
alignedWidth = (surface->iWidth + 1) >> 1; |
| 218 |
alignedHeight = surface->iHeight * 2; |
| 219 |
alignedFormat = Media_Format_Y216; |
| 220 |
break; |
| 221 |
case Media_Format_YUY2: |
| 222 |
alignedWidth = (surface->iWidth + 1) >> 1; |
| 223 |
alignedHeight = surface->iHeight * 2; |
| 224 |
break; |
| 225 |
case Media_Format_P016: |
| 226 |
case Media_Format_P012: |
| 227 |
case Media_Format_P010: |
| 228 |
alignedHeight = surface->iHeight; |
| 229 |
alignedWidth = surface->iWidth; |
| 230 |
if(entrypoint == VAEntrypointEncSlice) |
| 231 |
{ |
| 232 |
alignedWidth = surface->iWidth * 2; |
| 233 |
alignedFormat = Media_Format_NV12; |
| 234 |
} |
| 235 |
else |
| 236 |
{ |
| 237 |
alignedFormat = Media_Format_P016; |
| 238 |
} |
| 239 |
break; |
| 240 |
default: |
| 241 |
return surface; |
| 242 |
} |
| 243 |
|
| 244 |
//create new dst surface and copy the structure |
| 245 |
PDDI_MEDIA_SURFACE dstSurface = (DDI_MEDIA_SURFACE *)MOS_AllocAndZeroMemory(sizeof(DDI_MEDIA_SURFACE)); |
| 246 |
DDI_CHK_NULL(dstSurface, "nullptr dstSurface", nullptr); |
| 247 |
MOS_SecureMemcpy(dstSurface,sizeof(DDI_MEDIA_SURFACE),surface,sizeof(DDI_MEDIA_SURFACE)); |
| 248 |
|
| 249 |
dstSurface->uiVariantFlag = 1; |
| 250 |
dstSurface->format = alignedFormat; |
| 251 |
dstSurface->iWidth = alignedWidth; |
| 252 |
dstSurface->iHeight = alignedHeight; |
| 253 |
//CreateNewSurface |
| 254 |
if(MediaLibvaUtilNext::CreateSurface(dstSurface,mediaCtx) != VA_STATUS_SUCCESS) |
| 255 |
{ |
| 256 |
MOS_FreeMemory(dstSurface); |
| 257 |
return surface; |
| 258 |
} |
| 259 |
//replace the surface |
| 260 |
MosUtilities::MosLockMutex(&mediaCtx->SurfaceMutex); |
| 261 |
surfaceElement = (PDDI_MEDIA_SURFACE_HEAP_ELEMENT)surface->pMediaCtx->pSurfaceHeap->pHeapBase; |
| 262 |
surfaceElement += vaID; |
| 263 |
surfaceElement->pSurface = dstSurface; |
| 264 |
MosUtilities::MosUnlockMutex(&mediaCtx->SurfaceMutex); |
| 265 |
//FreeSurface |
| 266 |
MediaLibvaUtilNext::FreeSurface(surface); |
| 267 |
MOS_FreeMemory(surface); |
| 268 |
|
| 269 |
return dstSurface; |
| 270 |
} |
| 271 |
|
| 272 |
DDI_MEDIA_BUFFER* MediaLibvaCommonNext::GetBufferFromVABufferID( |
| 273 |
PDDI_MEDIA_CONTEXT mediaCtx, |
| 274 |
VABufferID bufferID) |
| 275 |
{ |
| 276 |
DDI_FUNC_ENTER; |
| 277 |
DDI_CHK_NULL(mediaCtx, "nullptr mediaCtx", nullptr); |
| 278 |
|
| 279 |
uint32_t i = 0; |
| 280 |
PDDI_MEDIA_BUFFER_HEAP_ELEMENT bufHeapElement = nullptr; |
| 281 |
PDDI_MEDIA_BUFFER buf = nullptr; |
| 282 |
|
| 283 |
i = (uint32_t)bufferID; |
| 284 |
DDI_CHK_LESS(i, mediaCtx->pBufferHeap->uiAllocatedHeapElements, "invalid buffer id", nullptr); |
| 285 |
|
| 286 |
MosUtilities::MosLockMutex(&mediaCtx->BufferMutex); |
| 287 |
bufHeapElement = (PDDI_MEDIA_BUFFER_HEAP_ELEMENT)mediaCtx->pBufferHeap->pHeapBase; |
| 288 |
bufHeapElement += i; |
| 289 |
buf = bufHeapElement->pBuffer; |
| 290 |
MosUtilities::MosUnlockMutex(&mediaCtx->BufferMutex); |
| 291 |
|
| 292 |
return buf; |
| 293 |
} |
| 294 |
|
| 295 |
void* MediaLibvaCommonNext::GetVaContextFromHeap( |
| 296 |
PDDI_MEDIA_HEAP mediaHeap, |
| 297 |
uint32_t index, |
| 298 |
PMOS_MUTEX mutex) |
| 299 |
{ |
| 300 |
PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT vaCtxHeapElmt = nullptr; |
| 301 |
void *context = nullptr; |
| 302 |
DDI_FUNC_ENTER; |
| 303 |
|
| 304 |
MosUtilities::MosLockMutex(mutex); |
| 305 |
if(nullptr == mediaHeap || index >= mediaHeap->uiAllocatedHeapElements) |
| 306 |
{ |
| 307 |
MosUtilities::MosUnlockMutex(mutex); |
| 308 |
return nullptr; |
| 309 |
} |
| 310 |
vaCtxHeapElmt = (PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT)mediaHeap->pHeapBase; |
| 311 |
vaCtxHeapElmt += index; |
| 312 |
context = vaCtxHeapElmt->pVaContext; |
| 313 |
MosUtilities::MosUnlockMutex(mutex); |
| 314 |
|
| 315 |
return context; |
| 316 |
} |
| 317 |
|
| 318 |
void* MediaLibvaCommonNext::GetContextFromContextID( |
| 319 |
VADriverContextP ctx, |
| 320 |
VAContextID vaCtxID, |
| 321 |
uint32_t *ctxType) |
| 322 |
{ |
| 323 |
PDDI_MEDIA_CONTEXT mediaCtx = nullptr; |
| 324 |
uint32_t index = 0; |
| 325 |
DDI_FUNC_ENTER; |
| 326 |
DDI_CHK_NULL(ctx, "nullptr ctx", nullptr); |
| 327 |
DDI_CHK_NULL(ctxType, "nullptr ctxType", nullptr); |
| 328 |
|
| 329 |
if (vaCtxID < DDI_MEDIA_VACONTEXTID_BASE) |
| 330 |
{ |
| 331 |
DDI_ASSERTMESSAGE("Invalid ContextID"); |
| 332 |
return nullptr; |
| 333 |
} |
| 334 |
mediaCtx = GetMediaContext(ctx); |
| 335 |
index = vaCtxID & DDI_MEDIA_MASK_VACONTEXTID; |
| 336 |
|
| 337 |
if (index >= DDI_MEDIA_MAX_INSTANCE_NUMBER) |
| 338 |
{ |
| 339 |
return nullptr; |
| 340 |
} |
| 341 |
|
| 342 |
if ((vaCtxID & DDI_MEDIA_MASK_VACONTEXT_TYPE) == DDI_MEDIA_SOFTLET_VACONTEXTID_DECODER_OFFSET) |
| 343 |
{ |
| 344 |
DDI_VERBOSEMESSAGE("Decode context detected: 0x%x", vaCtxID); |
| 345 |
*ctxType = DDI_MEDIA_CONTEXT_TYPE_DECODER; |
| 346 |
return GetVaContextFromHeap(mediaCtx->pDecoderCtxHeap, index, &mediaCtx->DecoderMutex); |
| 347 |
} |
| 348 |
else if ((vaCtxID & DDI_MEDIA_MASK_VACONTEXT_TYPE) == DDI_MEDIA_SOFTLET_VACONTEXTID_ENCODER_OFFSET) |
| 349 |
{ |
| 350 |
*ctxType = DDI_MEDIA_CONTEXT_TYPE_ENCODER; |
| 351 |
return GetVaContextFromHeap(mediaCtx->pEncoderCtxHeap, index, &mediaCtx->EncoderMutex); |
| 352 |
} |
| 353 |
else if ((vaCtxID & DDI_MEDIA_MASK_VACONTEXT_TYPE) == DDI_MEDIA_SOFTLET_VACONTEXTID_VP_OFFSET) |
| 354 |
{ |
| 355 |
*ctxType = DDI_MEDIA_CONTEXT_TYPE_VP; |
| 356 |
return GetVaContextFromHeap(mediaCtx->pVpCtxHeap, index, &mediaCtx->VpMutex); |
| 357 |
} |
| 358 |
else if ((vaCtxID & DDI_MEDIA_MASK_VACONTEXT_TYPE) == DDI_MEDIA_SOFTLET_VACONTEXTID_CP_OFFSET) |
| 359 |
{ |
| 360 |
DDI_VERBOSEMESSAGE("Protected session detected: 0x%x", vaCtxID); |
| 361 |
*ctxType = DDI_MEDIA_CONTEXT_TYPE_PROTECTED; |
| 362 |
index = index & DDI_MEDIA_MASK_VAPROTECTEDSESSION_ID; |
| 363 |
return GetVaContextFromHeap(mediaCtx->pProtCtxHeap, index, &mediaCtx->ProtMutex); |
| 364 |
} |
| 365 |
else |
| 366 |
{ |
| 367 |
DDI_ASSERTMESSAGE("Invalid context: 0x%x", vaCtxID); |
| 368 |
*ctxType = DDI_MEDIA_CONTEXT_TYPE_NONE; |
| 369 |
return nullptr; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
uint32_t MediaLibvaCommonNext::GetCtxTypeFromVABufferID(PDDI_MEDIA_CONTEXT mediaCtx, VABufferID bufferID) |
| 374 |
{ |
| 375 |
PDDI_MEDIA_BUFFER_HEAP_ELEMENT bufHeapElement = nullptr; |
| 376 |
uint32_t i = 0; |
| 377 |
uint32_t ctxType = DDI_MEDIA_CONTEXT_TYPE_NONE; |
| 378 |
|
| 379 |
DDI_FUNC_ENTER; |
| 380 |
DDI_CHK_NULL(mediaCtx, "nullptr mediaCtx", DDI_MEDIA_CONTEXT_TYPE_NONE); |
| 381 |
DDI_CHK_NULL(mediaCtx->pBufferHeap, "nullptr mediaCtx->pBufferHeap", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 382 |
|
| 383 |
i = (uint32_t)bufferID; |
| 384 |
DDI_CHK_LESS(i, mediaCtx->pBufferHeap->uiAllocatedHeapElements, "invalid buffer id", DDI_MEDIA_CONTEXT_TYPE_NONE); |
| 385 |
MosUtilities::MosLockMutex(&mediaCtx->BufferMutex); |
| 386 |
bufHeapElement = (PDDI_MEDIA_BUFFER_HEAP_ELEMENT)mediaCtx->pBufferHeap->pHeapBase; |
| 387 |
bufHeapElement += i; |
| 388 |
ctxType = bufHeapElement->uiCtxType; |
| 389 |
MosUtilities::MosUnlockMutex(&mediaCtx->BufferMutex); |
| 390 |
|
| 391 |
return ctxType; |
| 392 |
} |
| 393 |
|
| 394 |
void* MediaLibvaCommonNext::GetCtxFromVABufferID(PDDI_MEDIA_CONTEXT mediaCtx, VABufferID bufferID) |
| 395 |
{ |
| 396 |
uint32_t i = 0; |
| 397 |
PDDI_MEDIA_BUFFER_HEAP_ELEMENT bufHeapElement = nullptr; |
| 398 |
DDI_FUNC_ENTER; |
| 399 |
DDI_CHK_NULL(mediaCtx, "nullptr mediaCtx", nullptr); |
| 400 |
DDI_CHK_NULL(mediaCtx->pBufferHeap, "nullptr mediaCtx->pBufferHeap", nullptr); |
| 401 |
|
| 402 |
i = (uint32_t)bufferID; |
| 403 |
DDI_CHK_LESS(i, mediaCtx->pBufferHeap->uiAllocatedHeapElements, "invalid buffer id", nullptr); |
| 404 |
MosUtilities::MosLockMutex(&mediaCtx->BufferMutex); |
| 405 |
bufHeapElement = (PDDI_MEDIA_BUFFER_HEAP_ELEMENT)mediaCtx->pBufferHeap->pHeapBase; |
| 406 |
bufHeapElement += i; |
| 407 |
void *temp = bufHeapElement->pCtx; |
| 408 |
MosUtilities::MosUnlockMutex(&mediaCtx->BufferMutex); |
| 409 |
|
| 410 |
return temp; |
| 411 |
} |
| 412 |
|
| 413 |
int32_t MediaLibvaCommonNext::GetGpuPriority( |
| 414 |
VADriverContextP ctx, |
| 415 |
VABufferID *buffers, |
| 416 |
int32_t numBuffers, |
| 417 |
bool *updatePriority, |
| 418 |
int32_t *priority) |
| 419 |
{ |
| 420 |
void *data = nullptr; |
| 421 |
uint32_t updateSessionPriority = 0; |
| 422 |
uint32_t priorityValue = 0; |
| 423 |
int32_t priorityIndexInBuf = -1; |
| 424 |
PDDI_MEDIA_CONTEXT mediaCtx = nullptr; |
| 425 |
DDI_MEDIA_BUFFER *buf = nullptr; |
| 426 |
VAContextParameterUpdateBuffer *contextParamBuf = nullptr; |
| 427 |
|
| 428 |
DDI_FUNC_ENTER; |
| 429 |
DDI_CHK_NULL(ctx, "nullptr context in GetGpuPriority!", -1); |
| 430 |
|
| 431 |
mediaCtx = GetMediaContext(ctx); |
| 432 |
DDI_CHK_NULL(mediaCtx, "nullptr mediaCtx", -1); |
| 433 |
|
| 434 |
#if VA_CHECK_VERSION(1, 10, 0) |
| 435 |
for (int32_t i = 0; i < numBuffers; i++) |
| 436 |
{ |
| 437 |
buf = GetBufferFromVABufferID(mediaCtx, buffers[i]); |
| 438 |
DDI_CHK_NULL(buf, "Invalid buffer.", -1); |
| 439 |
|
| 440 |
if ((int32_t)buf->uiType == VAContextParameterUpdateBufferType) |
| 441 |
{ |
| 442 |
//Read the priority from the VAContextParameterUpdateBuffer |
| 443 |
MediaLibvaInterfaceNext::MapBuffer(ctx, buffers[i], &data); |
| 444 |
DDI_CHK_NULL(data, "nullptr data.", -1); |
| 445 |
|
| 446 |
contextParamBuf = (VAContextParameterUpdateBuffer *)data; |
| 447 |
DDI_CHK_NULL(contextParamBuf, "nullptr contextParamBuf.", -1); |
| 448 |
|
| 449 |
updateSessionPriority = contextParamBuf->flags.bits.context_priority_update; |
| 450 |
priorityValue = contextParamBuf->context_priority.bits.priority; |
| 451 |
|
| 452 |
if (updateSessionPriority) |
| 453 |
{ |
| 454 |
*updatePriority = true; |
| 455 |
if (priorityValue <= CONTEXT_PRIORITY_MAX) |
| 456 |
{ |
| 457 |
*priority = priorityValue - CONTEXT_PRIORITY_MAX / 2; |
| 458 |
} |
| 459 |
else |
| 460 |
{ |
| 461 |
*priority = 0; |
| 462 |
} |
| 463 |
} |
| 464 |
else |
| 465 |
{ |
| 466 |
*updatePriority = false; |
| 467 |
*priority = 0; |
| 468 |
} |
| 469 |
|
| 470 |
MediaLibvaInterfaceNext::UnmapBuffer(ctx, buffers[i]); |
| 471 |
priorityIndexInBuf = i; |
| 472 |
break; |
| 473 |
} |
| 474 |
} |
| 475 |
#endif |
| 476 |
return priorityIndexInBuf; |
| 477 |
} |
| 478 |
|
| 479 |
void MediaLibvaCommonNext::MovePriorityBufferIdToEnd(VABufferID *buffers, int32_t priorityIndexInBuf, int32_t numBuffers) |
| 480 |
{ |
| 481 |
VABufferID vaBufferID = 0; |
| 482 |
DDI_FUNC_ENTER; |
| 483 |
|
| 484 |
if( (numBuffers > 1) && (priorityIndexInBuf < numBuffers -1) ) |
| 485 |
{ |
| 486 |
vaBufferID = buffers[priorityIndexInBuf]; |
| 487 |
while(priorityIndexInBuf < (numBuffers - 1) ) |
| 488 |
{ |
| 489 |
buffers[priorityIndexInBuf] = buffers[priorityIndexInBuf+1]; |
| 490 |
priorityIndexInBuf++; |
| 491 |
} |
| 492 |
buffers[numBuffers -1] = vaBufferID; |
| 493 |
} |
| 494 |
return; |
| 495 |
} |