| 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 ddi_media_functions.cpp |
| 24 |
//! \brief ddi media functions implementaion. |
| 25 |
//! |
| 26 |
#include "ddi_media_functions.h" |
| 27 |
#include "media_libva_util_next.h" |
| 28 |
#include "media_libva_interface_next.h" |
| 29 |
#include "media_libva_caps_next.h" |
| 30 |
|
| 31 |
const VAProcColorStandardType DdiMediaFunctions::m_vpInputColorStd[DDI_VP_NUM_INPUT_COLOR_STD] = { |
| 32 |
VAProcColorStandardBT601, |
| 33 |
VAProcColorStandardBT709, |
| 34 |
VAProcColorStandardSRGB, |
| 35 |
VAProcColorStandardSTRGB, |
| 36 |
VAProcColorStandardBT2020, |
| 37 |
VAProcColorStandardExplicit |
| 38 |
}; |
| 39 |
|
| 40 |
const VAProcColorStandardType DdiMediaFunctions::m_vpOutputColorStd[DDI_VP_NUM_OUT_COLOR_STD] = { |
| 41 |
VAProcColorStandardBT601, |
| 42 |
VAProcColorStandardBT709, |
| 43 |
VAProcColorStandardSRGB, |
| 44 |
VAProcColorStandardSTRGB, |
| 45 |
VAProcColorStandardBT2020, |
| 46 |
VAProcColorStandardExplicit |
| 47 |
}; |
| 48 |
|
| 49 |
VAStatus DdiMediaFunctions::CreateContext ( |
| 50 |
VADriverContextP ctx, |
| 51 |
VAConfigID configId, |
| 52 |
int32_t pictureWidth, |
| 53 |
int32_t pictureHeight, |
| 54 |
int32_t flag, |
| 55 |
VASurfaceID *renderTargets, |
| 56 |
int32_t renderTargetsNum, |
| 57 |
VAContextID *context) |
| 58 |
{ |
| 59 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 60 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 61 |
} |
| 62 |
|
| 63 |
VAStatus DdiMediaFunctions::DestroyContext ( |
| 64 |
VADriverContextP ctx, |
| 65 |
VAContextID context) |
| 66 |
{ |
| 67 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 68 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 69 |
} |
| 70 |
|
| 71 |
VAStatus DdiMediaFunctions::CreateBuffer ( |
| 72 |
VADriverContextP ctx, |
| 73 |
VAContextID context, |
| 74 |
VABufferType type, |
| 75 |
uint32_t size, |
| 76 |
uint32_t elementsNum, |
| 77 |
void *data, |
| 78 |
VABufferID *bufId) |
| 79 |
{ |
| 80 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 81 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 82 |
} |
| 83 |
|
| 84 |
VAStatus DdiMediaFunctions::MapBufferInternal( |
| 85 |
DDI_MEDIA_CONTEXT *mediaCtx, |
| 86 |
VABufferID bufId, |
| 87 |
void **buf, |
| 88 |
uint32_t flag) |
| 89 |
{ |
| 90 |
VAStatus vaStatus = VA_STATUS_SUCCESS; |
| 91 |
DDI_MEDIA_BUFFER *mediaBuf = nullptr; |
| 92 |
|
| 93 |
DDI_FUNC_ENTER; |
| 94 |
|
| 95 |
mediaBuf = MediaLibvaCommonNext::GetBufferFromVABufferID(mediaCtx, bufId); |
| 96 |
DDI_CHK_NULL(mediaBuf, "nullptr mediaBuf", VA_STATUS_ERROR_INVALID_BUFFER); |
| 97 |
|
| 98 |
switch((int32_t)mediaBuf->uiType) |
| 99 |
{ |
| 100 |
case VAImageBufferType: |
| 101 |
default: |
| 102 |
if((mediaBuf->format != Media_Format_CPU) && (MediaLibvaInterfaceNext::MediaFormatToOsFormat(mediaBuf->format) != VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT)) |
| 103 |
{ |
| 104 |
MosUtilities::MosLockMutex(&mediaCtx->BufferMutex); |
| 105 |
// A critical section starts. |
| 106 |
// Make sure not to bailout with a return until the section ends. |
| 107 |
if (nullptr != mediaBuf->pSurface && Media_Format_CPU != mediaBuf->format) |
| 108 |
{ |
| 109 |
vaStatus = MediaLibvaInterfaceNext::MediaMemoryDecompress(mediaCtx, mediaBuf->pSurface); |
| 110 |
} |
| 111 |
|
| 112 |
if (VA_STATUS_SUCCESS == vaStatus) |
| 113 |
{ |
| 114 |
*buf = MediaLibvaUtilNext::LockBuffer(mediaBuf, flag); |
| 115 |
if (nullptr == *buf) |
| 116 |
{ |
| 117 |
vaStatus = VA_STATUS_ERROR_OPERATION_FAILED; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
// The critical section ends. |
| 122 |
MosUtilities::MosUnlockMutex(&mediaCtx->BufferMutex); |
| 123 |
} |
| 124 |
else |
| 125 |
{ |
| 126 |
*buf = (void *)(mediaBuf->pData + mediaBuf->uiOffset); |
| 127 |
} |
| 128 |
break; |
| 129 |
} |
| 130 |
return vaStatus; |
| 131 |
} |
| 132 |
|
| 133 |
VAStatus DdiMediaFunctions::UnmapBuffer ( |
| 134 |
DDI_MEDIA_CONTEXT *mediaCtx, |
| 135 |
VABufferID bufId) |
| 136 |
{ |
| 137 |
DDI_MEDIA_BUFFER *mediaBuf = nullptr; |
| 138 |
DDI_FUNC_ENTER; |
| 139 |
DDI_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 140 |
|
| 141 |
mediaBuf = MediaLibvaCommonNext::GetBufferFromVABufferID(mediaCtx, bufId); |
| 142 |
DDI_CHK_NULL(mediaBuf, "nullptr mediaBuf", VA_STATUS_ERROR_INVALID_BUFFER); |
| 143 |
|
| 144 |
switch ((int32_t)mediaBuf->uiType) |
| 145 |
{ |
| 146 |
case VAImageBufferType: |
| 147 |
default: |
| 148 |
if((mediaBuf->format != Media_Format_CPU) && (MediaLibvaInterfaceNext::MediaFormatToOsFormat(mediaBuf->format) != VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT)) |
| 149 |
{ |
| 150 |
MosUtilities::MosLockMutex(&mediaCtx->BufferMutex); |
| 151 |
MediaLibvaUtilNext::UnlockBuffer(mediaBuf); |
| 152 |
MosUtilities::MosUnlockMutex(&mediaCtx->BufferMutex); |
| 153 |
} |
| 154 |
break; |
| 155 |
} |
| 156 |
return VA_STATUS_SUCCESS; |
| 157 |
} |
| 158 |
|
| 159 |
VAStatus DdiMediaFunctions::DestroyBuffer( |
| 160 |
DDI_MEDIA_CONTEXT *mediaCtx, |
| 161 |
VABufferID bufId) |
| 162 |
{ |
| 163 |
DDI_MEDIA_BUFFER *buf = nullptr; |
| 164 |
DDI_FUNC_ENTER; |
| 165 |
|
| 166 |
buf = MediaLibvaCommonNext::GetBufferFromVABufferID(mediaCtx, bufId); |
| 167 |
DDI_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_BUFFER); |
| 168 |
|
| 169 |
switch((int32_t)buf->uiType) |
| 170 |
{ |
| 171 |
case VAImageBufferType: |
| 172 |
if(buf->format == Media_Format_CPU) |
| 173 |
{ |
| 174 |
MOS_DeleteArray(buf->pData); |
| 175 |
} |
| 176 |
else |
| 177 |
{ |
| 178 |
MediaLibvaUtilNext::UnRefBufObjInMediaBuffer(buf); |
| 179 |
|
| 180 |
if (buf->uiExportcount) |
| 181 |
{ |
| 182 |
buf->bPostponedBufFree = true; |
| 183 |
MOS_TraceEventExt(EVENT_VA_FREE_BUFFER, EVENT_TYPE_END, nullptr, 0, nullptr, 0); |
| 184 |
return VA_STATUS_SUCCESS; |
| 185 |
} |
| 186 |
} |
| 187 |
break; |
| 188 |
case VAStatsStatisticsParameterBufferType: |
| 189 |
default: // do not handle any un-listed buffer type |
| 190 |
MOS_DeleteArray(buf->pData); |
| 191 |
break; |
| 192 |
} |
| 193 |
MOS_Delete(buf); |
| 194 |
MediaLibvaInterfaceNext::DestroyBufFromVABufferID(mediaCtx, bufId); |
| 195 |
|
| 196 |
return VA_STATUS_SUCCESS; |
| 197 |
} |
| 198 |
|
| 199 |
VAStatus DdiMediaFunctions::BeginPicture ( |
| 200 |
VADriverContextP ctx, |
| 201 |
VAContextID context, |
| 202 |
VASurfaceID renderTarget) |
| 203 |
{ |
| 204 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 205 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 206 |
} |
| 207 |
|
| 208 |
VAStatus DdiMediaFunctions::RenderPicture ( |
| 209 |
VADriverContextP ctx, |
| 210 |
VAContextID context, |
| 211 |
VABufferID *buffers, |
| 212 |
int32_t buffersNum) |
| 213 |
{ |
| 214 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 215 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 216 |
} |
| 217 |
|
| 218 |
VAStatus DdiMediaFunctions::EndPicture ( |
| 219 |
VADriverContextP ctx, |
| 220 |
VAContextID context) |
| 221 |
{ |
| 222 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 223 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 224 |
} |
| 225 |
|
| 226 |
VAStatus DdiMediaFunctions::CreateConfig ( |
| 227 |
VADriverContextP ctx, |
| 228 |
VAProfile profile, |
| 229 |
VAEntrypoint entrypoint, |
| 230 |
VAConfigAttrib *attribList, |
| 231 |
int32_t attribsNum, |
| 232 |
VAConfigID *configId) |
| 233 |
{ |
| 234 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 235 |
DDI_CODEC_FUNC_ENTER; |
| 236 |
|
| 237 |
VAStatus status = VA_STATUS_SUCCESS; |
| 238 |
DDI_CODEC_CHK_NULL(configId, "nullptr configId", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 239 |
if(attribsNum) |
| 240 |
{ |
| 241 |
DDI_CODEC_CHK_NULL(attribList, "nullptr attribList", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 242 |
} |
| 243 |
|
| 244 |
PDDI_MEDIA_CONTEXT mediaCtx = GetMediaContext(ctx); |
| 245 |
DDI_CODEC_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 246 |
DDI_CODEC_CHK_NULL(mediaCtx->m_capsNext, "nullptr m_caps", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 247 |
DDI_CODEC_CHK_NULL(mediaCtx->m_capsNext->m_capsTable, "nullptr m_capsTable", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 248 |
|
| 249 |
status = mediaCtx->m_capsNext->CreateConfig(profile, entrypoint, attribList, attribsNum, configId); |
| 250 |
DDI_CODEC_CHK_RET(status, "Create common config failed"); |
| 251 |
|
| 252 |
return status; |
| 253 |
} |
| 254 |
|
| 255 |
VAStatus DdiMediaFunctions::QueryVideoProcFilters( |
| 256 |
VADriverContextP ctx, |
| 257 |
VAContextID context, |
| 258 |
VAProcFilterType *filters, |
| 259 |
uint32_t *filtersNum) |
| 260 |
{ |
| 261 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 262 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 263 |
} |
| 264 |
|
| 265 |
VAStatus DdiMediaFunctions::QueryVideoProcFilterCaps( |
| 266 |
VADriverContextP ctx, |
| 267 |
VAContextID context, |
| 268 |
VAProcFilterType type, |
| 269 |
void *filterCaps, |
| 270 |
uint32_t *filterCapsNum) |
| 271 |
{ |
| 272 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 273 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 274 |
} |
| 275 |
|
| 276 |
VAStatus DdiMediaFunctions::QueryVideoProcPipelineCaps( |
| 277 |
VADriverContextP ctx, |
| 278 |
VAContextID context, |
| 279 |
VABufferID *filters, |
| 280 |
uint32_t filtersNum, |
| 281 |
VAProcPipelineCaps *pipelineCaps) |
| 282 |
{ |
| 283 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 284 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 285 |
} |
| 286 |
|
| 287 |
#if VA_CHECK_VERSION(1,11,0) |
| 288 |
VAStatus DdiMediaFunctions::CreateProtectedSession( |
| 289 |
VADriverContextP ctx, |
| 290 |
VAConfigID configId, |
| 291 |
VAProtectedSessionID *protectedSession) |
| 292 |
{ |
| 293 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 294 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 295 |
} |
| 296 |
|
| 297 |
VAStatus DdiMediaFunctions::DestroyProtectedSession( |
| 298 |
VADriverContextP ctx, |
| 299 |
VAProtectedSessionID protectedSession) |
| 300 |
{ |
| 301 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 302 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 303 |
} |
| 304 |
|
| 305 |
VAStatus DdiMediaFunctions::AttachProtectedSession( |
| 306 |
VADriverContextP ctx, |
| 307 |
VAContextID context, |
| 308 |
VAProtectedSessionID protectedSession) |
| 309 |
{ |
| 310 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 311 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 312 |
} |
| 313 |
|
| 314 |
VAStatus DdiMediaFunctions::DetachProtectedSession( |
| 315 |
VADriverContextP ctx, |
| 316 |
VAContextID context) |
| 317 |
{ |
| 318 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 319 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 320 |
} |
| 321 |
|
| 322 |
VAStatus DdiMediaFunctions::ProtectedSessionExecute( |
| 323 |
VADriverContextP ctx, |
| 324 |
VAProtectedSessionID protectedSession, |
| 325 |
VABufferID data) |
| 326 |
{ |
| 327 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 328 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 329 |
} |
| 330 |
#endif |
| 331 |
|
| 332 |
VAStatus DdiMediaFunctions::StatusCheck( |
| 333 |
PDDI_MEDIA_CONTEXT mediaCtx, |
| 334 |
DDI_MEDIA_SURFACE *surface, |
| 335 |
VASurfaceID surfaceId) |
| 336 |
{ |
| 337 |
return VA_STATUS_SUCCESS; |
| 338 |
} |
| 339 |
|
| 340 |
VAStatus DdiMediaFunctions::QuerySurfaceError( |
| 341 |
VADriverContextP ctx, |
| 342 |
VASurfaceID renderTarget, |
| 343 |
VAStatus errorStatus, |
| 344 |
void **errorInfo) |
| 345 |
{ |
| 346 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 347 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 348 |
} |
| 349 |
|
| 350 |
VAStatus DdiMediaFunctions::PutSurface( |
| 351 |
VADriverContextP ctx, |
| 352 |
VASurfaceID surface, |
| 353 |
void *draw, |
| 354 |
int16_t srcx, |
| 355 |
int16_t srcy, |
| 356 |
uint16_t srcw, |
| 357 |
uint16_t srch, |
| 358 |
int16_t destx, |
| 359 |
int16_t desty, |
| 360 |
uint16_t destw, |
| 361 |
uint16_t desth, |
| 362 |
VARectangle *cliprects, |
| 363 |
uint32_t numberCliprects, |
| 364 |
uint32_t flags) |
| 365 |
{ |
| 366 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 367 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 368 |
} |
| 369 |
|
| 370 |
VAStatus DdiMediaFunctions::ProcessPipeline( |
| 371 |
VADriverContextP vaDrvCtx, |
| 372 |
VAContextID ctxID, |
| 373 |
VASurfaceID srcSurface, |
| 374 |
VARectangle *srcRect, |
| 375 |
VASurfaceID dstSurface, |
| 376 |
VARectangle *dstRect |
| 377 |
) |
| 378 |
{ |
| 379 |
DDI_ASSERTMESSAGE("Unsupported function call."); |
| 380 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 381 |
} |