| 1 |
/* |
| 2 |
* Copyright (c) 2009-2020, 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_encoder.cpp |
| 24 |
//! \brief libva(and its extension) encoder implementation |
| 25 |
//! |
| 26 |
#include <unistd.h> |
| 27 |
#include "media_libva_encoder.h" |
| 28 |
#include "media_ddi_encode_base.h" |
| 29 |
#include "media_libva_util.h" |
| 30 |
#include "media_libva_caps.h" |
| 31 |
#include "media_ddi_factory.h" |
| 32 |
|
| 33 |
#include "hwinfo_linux.h" |
| 34 |
#include "codechal_memdecomp.h" |
| 35 |
#include "media_interfaces_codechal.h" |
| 36 |
#include "media_interfaces_codechal_next.h" |
| 37 |
#include "media_interfaces_mmd.h" |
| 38 |
#include "cm_device_rt.h" |
| 39 |
|
| 40 |
typedef MediaDdiFactoryNoArg<DdiEncodeBase> DdiEncodeFactory; |
| 41 |
|
| 42 |
PDDI_ENCODE_CONTEXT DdiEncode_GetEncContextFromContextID(VADriverContextP ctx, VAContextID vaCtxID) |
| 43 |
{ |
| 44 |
uint32_t ctxType; |
| 45 |
return (PDDI_ENCODE_CONTEXT)DdiMedia_GetContextFromContextID(ctx, vaCtxID, &ctxType); |
| 46 |
} |
| 47 |
|
| 48 |
VAStatus DdiEncode_RemoveFromStatusReportQueue( |
| 49 |
PDDI_ENCODE_CONTEXT encCtx, |
| 50 |
PDDI_MEDIA_BUFFER buf) |
| 51 |
|
| 52 |
{ |
| 53 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 54 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 55 |
DDI_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 56 |
|
| 57 |
VAStatus vaStatus = encCtx->m_encode->RemoveFromStatusReportQueue(buf); |
| 58 |
|
| 59 |
return vaStatus; |
| 60 |
} |
| 61 |
|
| 62 |
VAStatus DdiEncode_RemoveFromEncStatusReportQueue( |
| 63 |
PDDI_ENCODE_CONTEXT encCtx, |
| 64 |
PDDI_MEDIA_BUFFER buf, |
| 65 |
DDI_ENCODE_FEI_ENC_BUFFER_TYPE typeIdx) |
| 66 |
{ |
| 67 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 68 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 69 |
DDI_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 70 |
|
| 71 |
VAStatus vaStatus = encCtx->m_encode->RemoveFromEncStatusReportQueue(buf, typeIdx); |
| 72 |
|
| 73 |
return vaStatus; |
| 74 |
} |
| 75 |
|
| 76 |
VAStatus DdiEncode_RemoveFromPreEncStatusReportQueue( |
| 77 |
PDDI_ENCODE_CONTEXT encCtx, |
| 78 |
PDDI_MEDIA_BUFFER buf, |
| 79 |
DDI_ENCODE_PRE_ENC_BUFFER_TYPE typeIdx) |
| 80 |
{ |
| 81 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 82 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 83 |
DDI_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 84 |
|
| 85 |
VAStatus vaStatus = encCtx->m_encode->RemoveFromPreEncStatusReportQueue(buf, typeIdx); |
| 86 |
|
| 87 |
return vaStatus; |
| 88 |
} |
| 89 |
|
| 90 |
bool DdiEncode_CodedBufferExistInStatusReport( |
| 91 |
PDDI_ENCODE_CONTEXT encCtx, |
| 92 |
PDDI_MEDIA_BUFFER buf) |
| 93 |
{ |
| 94 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 95 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 96 |
DDI_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 97 |
|
| 98 |
return encCtx->m_encode->CodedBufferExistInStatusReport(buf); |
| 99 |
} |
| 100 |
|
| 101 |
bool DdiEncode_EncBufferExistInStatusReport( |
| 102 |
PDDI_ENCODE_CONTEXT encCtx, |
| 103 |
PDDI_MEDIA_BUFFER buf, |
| 104 |
DDI_ENCODE_FEI_ENC_BUFFER_TYPE typeIdx) |
| 105 |
{ |
| 106 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 107 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 108 |
DDI_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 109 |
|
| 110 |
return encCtx->m_encode->EncBufferExistInStatusReport(buf, typeIdx); |
| 111 |
} |
| 112 |
|
| 113 |
bool DdiEncode_PreEncBufferExistInStatusReport( |
| 114 |
PDDI_ENCODE_CONTEXT encCtx, |
| 115 |
PDDI_MEDIA_BUFFER buf, |
| 116 |
DDI_ENCODE_PRE_ENC_BUFFER_TYPE typeIdx) |
| 117 |
{ |
| 118 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 119 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 120 |
DDI_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 121 |
|
| 122 |
return encCtx->m_encode->PreEncBufferExistInStatusReport(buf, typeIdx); |
| 123 |
} |
| 124 |
|
| 125 |
VAStatus DdiEncode_EncStatusReport( |
| 126 |
PDDI_ENCODE_CONTEXT encCtx, |
| 127 |
DDI_MEDIA_BUFFER *mediaBuf, |
| 128 |
void **buf) |
| 129 |
{ |
| 130 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 131 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 132 |
DDI_CHK_NULL(mediaBuf, "nullptr mediaBuf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 133 |
DDI_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 134 |
|
| 135 |
VAStatus vaStatus = encCtx->m_encode->EncStatusReport(mediaBuf, buf); |
| 136 |
|
| 137 |
return vaStatus; |
| 138 |
} |
| 139 |
|
| 140 |
VAStatus DdiEncode_PreEncStatusReport( |
| 141 |
PDDI_ENCODE_CONTEXT encCtx, |
| 142 |
DDI_MEDIA_BUFFER *mediaBuf, |
| 143 |
void **buf) |
| 144 |
{ |
| 145 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 146 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 147 |
DDI_CHK_NULL(mediaBuf, "nullptr mediaBuf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 148 |
DDI_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 149 |
|
| 150 |
VAStatus vaStatus = encCtx->m_encode->PreEncStatusReport(mediaBuf, buf); |
| 151 |
|
| 152 |
return vaStatus; |
| 153 |
} |
| 154 |
|
| 155 |
VAStatus DdiEncode_StatusReport( |
| 156 |
PDDI_ENCODE_CONTEXT encCtx, |
| 157 |
DDI_MEDIA_BUFFER *mediaBuf, |
| 158 |
void **buf) |
| 159 |
{ |
| 160 |
PERF_UTILITY_AUTO(__FUNCTION__, PERF_ENCODE, PERF_LEVEL_DDI); |
| 161 |
|
| 162 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 163 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 164 |
DDI_CHK_NULL(mediaBuf, "nullptr mediaBuf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 165 |
DDI_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 166 |
|
| 167 |
VAStatus vaStatus = encCtx->m_encode->StatusReport(mediaBuf, buf); |
| 168 |
|
| 169 |
return vaStatus; |
| 170 |
} |
| 171 |
|
| 172 |
//! |
| 173 |
//! \brief Clean and free encode context structure |
| 174 |
//! |
| 175 |
//! \param [in] encCtx |
| 176 |
//! Pointer to ddi encode context |
| 177 |
//! |
| 178 |
void DdiEncodeCleanUp(PDDI_ENCODE_CONTEXT encCtx) |
| 179 |
{ |
| 180 |
if (encCtx->m_encode) |
| 181 |
{ |
| 182 |
MOS_Delete(encCtx->m_encode); |
| 183 |
encCtx->m_encode = nullptr; |
| 184 |
} |
| 185 |
|
| 186 |
if (encCtx->pCpDdiInterface) |
| 187 |
{ |
| 188 |
Delete_DdiCpInterface(encCtx->pCpDdiInterface); |
| 189 |
encCtx->pCpDdiInterface = nullptr; |
| 190 |
} |
| 191 |
|
| 192 |
MOS_FreeMemory(encCtx); |
| 193 |
encCtx = nullptr; |
| 194 |
|
| 195 |
return; |
| 196 |
} |
| 197 |
|
| 198 |
/* |
| 199 |
* vpgEncodeCreateContext - Create an encode context |
| 200 |
* dpy: display |
| 201 |
* config_id: configuration for the encode context |
| 202 |
* picture_width: encode picture width |
| 203 |
* picture_height: encode picture height |
| 204 |
* flag: any combination of the following: |
| 205 |
* VA_PROGRESSIVE (only progressive frame pictures in the sequence when set) |
| 206 |
* render_targets: render targets (surfaces) tied to the context |
| 207 |
* num_render_targets: number of render targets in the above array |
| 208 |
* context: created context id upon return |
| 209 |
*/ |
| 210 |
VAStatus DdiEncode_CreateContext( |
| 211 |
VADriverContextP ctx, |
| 212 |
VAConfigID config_id, |
| 213 |
int32_t picture_width, |
| 214 |
int32_t picture_height, |
| 215 |
int32_t flag, |
| 216 |
VASurfaceID *render_targets, |
| 217 |
int32_t num_render_targets, |
| 218 |
VAContextID *context) |
| 219 |
{ |
| 220 |
PERF_UTILITY_AUTO(__FUNCTION__, PERF_ENCODE, PERF_LEVEL_DDI); |
| 221 |
|
| 222 |
DDI_CHK_NULL(ctx, "nullptr ctx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 223 |
DDI_CHK_NULL(ctx->pDriverData, "nullptr ctx->pDriverData", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 224 |
|
| 225 |
PDDI_MEDIA_CONTEXT mediaDrvCtx = DdiMedia_GetMediaContext(ctx); |
| 226 |
DDI_CHK_NULL(mediaDrvCtx->m_caps, "nullptr m_caps", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 227 |
|
| 228 |
VAProfile profile; |
| 229 |
VAEntrypoint entrypoint; |
| 230 |
uint32_t rcMode = 0; |
| 231 |
uint32_t feiFunction = 0; |
| 232 |
VAStatus vaStatus = mediaDrvCtx->m_caps->GetEncConfigAttr( |
| 233 |
config_id + DDI_CODEC_GEN_CONFIG_ATTRIBUTES_ENC_BASE, |
| 234 |
&profile, |
| 235 |
&entrypoint, |
| 236 |
&rcMode, |
| 237 |
&feiFunction); |
| 238 |
DDI_CHK_RET(vaStatus, "Invalide config_id!"); |
| 239 |
|
| 240 |
vaStatus = mediaDrvCtx->m_caps->CheckEncodeResolution( |
| 241 |
profile, |
| 242 |
picture_width, |
| 243 |
picture_height); |
| 244 |
if (vaStatus != VA_STATUS_SUCCESS) |
| 245 |
{ |
| 246 |
return VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED; |
| 247 |
} |
| 248 |
|
| 249 |
if (num_render_targets > DDI_MEDIA_MAX_SURFACE_NUMBER_CONTEXT) |
| 250 |
{ |
| 251 |
return VA_STATUS_ERROR_MAX_NUM_EXCEEDED; |
| 252 |
} |
| 253 |
|
| 254 |
std::string encodeKey = mediaDrvCtx->m_caps->GetEncodeCodecKey(profile, entrypoint, feiFunction); |
| 255 |
DdiEncodeBase *ddiEncode = DdiEncodeFactory::CreateCodec(encodeKey); |
| 256 |
DDI_CHK_NULL(ddiEncode, "nullptr ddiEncode", VA_STATUS_ERROR_UNIMPLEMENTED); |
| 257 |
|
| 258 |
// first create encoder context |
| 259 |
ddiEncode->m_encodeCtx = (PDDI_ENCODE_CONTEXT)MOS_AllocAndZeroMemory(sizeof(DDI_ENCODE_CONTEXT)); |
| 260 |
DDI_CHK_NULL(ddiEncode->m_encodeCtx, "nullptr ddiEncode->m_encodeCtx", VA_STATUS_ERROR_ALLOCATION_FAILED); |
| 261 |
|
| 262 |
PDDI_ENCODE_CONTEXT encCtx = ddiEncode->m_encodeCtx; |
| 263 |
encCtx->m_encode = ddiEncode; |
| 264 |
|
| 265 |
//initialize DDI level cp interface |
| 266 |
MOS_CONTEXT mosCtx = { }; |
| 267 |
encCtx->pCpDdiInterface = Create_DdiCpInterface(mosCtx); |
| 268 |
if (nullptr == encCtx->pCpDdiInterface) |
| 269 |
{ |
| 270 |
vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; |
| 271 |
DdiEncodeCleanUp(encCtx); |
| 272 |
return vaStatus; |
| 273 |
} |
| 274 |
|
| 275 |
// Get the buf manager for codechal create |
| 276 |
mosCtx.bufmgr = mediaDrvCtx->pDrmBufMgr; |
| 277 |
mosCtx.m_gpuContextMgr = mediaDrvCtx->m_gpuContextMgr; |
| 278 |
mosCtx.m_cmdBufMgr = mediaDrvCtx->m_cmdBufMgr; |
| 279 |
mosCtx.fd = mediaDrvCtx->fd; |
| 280 |
mosCtx.iDeviceId = mediaDrvCtx->iDeviceId; |
| 281 |
mosCtx.m_skuTable = mediaDrvCtx->SkuTable; |
| 282 |
mosCtx.m_waTable = mediaDrvCtx->WaTable; |
| 283 |
mosCtx.m_gtSystemInfo = *mediaDrvCtx->pGtSystemInfo; |
| 284 |
mosCtx.m_platform = mediaDrvCtx->platform; |
| 285 |
|
| 286 |
mosCtx.ppMediaMemDecompState = &mediaDrvCtx->pMediaMemDecompState; |
| 287 |
mosCtx.pfnMemoryDecompress = mediaDrvCtx->pfnMemoryDecompress; |
| 288 |
mosCtx.pfnMediaMemoryCopy = mediaDrvCtx->pfnMediaMemoryCopy; |
| 289 |
mosCtx.pfnMediaMemoryCopy2D = mediaDrvCtx->pfnMediaMemoryCopy2D; |
| 290 |
mosCtx.ppMediaCopyState = &mediaDrvCtx->pMediaCopyState; |
| 291 |
mosCtx.m_gtSystemInfo = *mediaDrvCtx->pGtSystemInfo; |
| 292 |
mosCtx.m_auxTableMgr = mediaDrvCtx->m_auxTableMgr; |
| 293 |
mosCtx.pGmmClientContext = mediaDrvCtx->pGmmClientContext; |
| 294 |
|
| 295 |
mosCtx.m_osDeviceContext = mediaDrvCtx->m_osDeviceContext; |
| 296 |
mosCtx.m_apoMosEnabled = mediaDrvCtx->m_apoMosEnabled; |
| 297 |
|
| 298 |
mosCtx.m_userSettingPtr = mediaDrvCtx->m_userSettingPtr; |
| 299 |
|
| 300 |
mosCtx.pPerfData = (PERF_DATA *)MOS_AllocAndZeroMemory(sizeof(PERF_DATA)); |
| 301 |
if (nullptr == mosCtx.pPerfData) |
| 302 |
{ |
| 303 |
vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; |
| 304 |
DdiEncodeCleanUp(encCtx); |
| 305 |
return vaStatus; |
| 306 |
} |
| 307 |
|
| 308 |
encCtx->vaEntrypoint = entrypoint; |
| 309 |
encCtx->vaProfile = profile; |
| 310 |
encCtx->uiRCMethod = rcMode; |
| 311 |
encCtx->wModeType = mediaDrvCtx->m_caps->GetEncodeCodecMode(profile, entrypoint); |
| 312 |
encCtx->codecFunction = mediaDrvCtx->m_caps->GetEncodeCodecFunction(profile, entrypoint, feiFunction); |
| 313 |
|
| 314 |
if (entrypoint == VAEntrypointEncSliceLP) |
| 315 |
{ |
| 316 |
encCtx->bVdencActive = true; |
| 317 |
} |
| 318 |
|
| 319 |
//Both dual pipe and LP pipe should support 10bit for below profiles |
| 320 |
// - HEVCMain10 profile |
| 321 |
// - VAProfileVP9Profile2 |
| 322 |
// - VAProfileVP9Profile3 |
| 323 |
if (profile == VAProfileVP9Profile2 || |
| 324 |
profile == VAProfileVP9Profile3) |
| 325 |
{ |
| 326 |
encCtx->m_encode->m_is10Bit = true; |
| 327 |
} |
| 328 |
|
| 329 |
if (profile == VAProfileVP9Profile1 || |
| 330 |
profile == VAProfileVP9Profile3) |
| 331 |
{ |
| 332 |
encCtx->m_encode->m_chromaFormat = DdiEncodeBase::yuv444; |
| 333 |
} |
| 334 |
|
| 335 |
CODECHAL_STANDARD_INFO standardInfo; |
| 336 |
MOS_ZeroMemory(&standardInfo, sizeof(CODECHAL_STANDARD_INFO)); |
| 337 |
standardInfo.CodecFunction = encCtx->codecFunction; |
| 338 |
standardInfo.Mode = encCtx->wModeType; |
| 339 |
Codechal *pCodecHal = CodechalDevice::CreateFactory( |
| 340 |
nullptr, |
| 341 |
&mosCtx, |
| 342 |
&standardInfo, |
| 343 |
nullptr); |
| 344 |
if (pCodecHal == nullptr) |
| 345 |
{ |
| 346 |
pCodecHal = CodechalDeviceNext::CreateFactory( |
| 347 |
nullptr, |
| 348 |
&mosCtx, |
| 349 |
&standardInfo, |
| 350 |
nullptr); |
| 351 |
|
| 352 |
if (nullptr == pCodecHal) |
| 353 |
{ |
| 354 |
// add anything necessary here to free the resource |
| 355 |
vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; |
| 356 |
DdiEncodeCleanUp(encCtx); |
| 357 |
return vaStatus; |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
encCtx->pCodecHal = pCodecHal; |
| 362 |
|
| 363 |
// Setup some initial data |
| 364 |
encCtx->dworiFrameWidth = picture_width; |
| 365 |
encCtx->dworiFrameHeight = picture_height; |
| 366 |
encCtx->wPicWidthInMB = (uint16_t)(DDI_CODEC_NUM_MACROBLOCKS_WIDTH(picture_width)); |
| 367 |
encCtx->wPicHeightInMB = (uint16_t)(DDI_CODEC_NUM_MACROBLOCKS_HEIGHT(picture_height)); |
| 368 |
encCtx->dwFrameWidth = encCtx->wPicWidthInMB * CODECHAL_MACROBLOCK_WIDTH; |
| 369 |
encCtx->dwFrameHeight = encCtx->wPicHeightInMB * CODECHAL_MACROBLOCK_HEIGHT; |
| 370 |
//recoder old resolution for dynamic resolution change |
| 371 |
encCtx->wContextPicWidthInMB = encCtx->wPicWidthInMB; |
| 372 |
encCtx->wContextPicHeightInMB = encCtx->wPicHeightInMB; |
| 373 |
encCtx->wOriPicWidthInMB = encCtx->wPicWidthInMB; |
| 374 |
encCtx->wOriPicHeightInMB = encCtx->wPicHeightInMB; |
| 375 |
encCtx->targetUsage = TARGETUSAGE_RT_SPEED; |
| 376 |
// Attach PMEDIDA_DRIVER_CONTEXT |
| 377 |
encCtx->pMediaCtx = mediaDrvCtx; |
| 378 |
|
| 379 |
encCtx->pCpDdiInterface->SetCpFlags(flag); |
| 380 |
encCtx->pCpDdiInterface->SetCpParams(CP_TYPE_NONE, encCtx->m_encode->m_codechalSettings); |
| 381 |
|
| 382 |
vaStatus = encCtx->m_encode->ContextInitialize(encCtx->m_encode->m_codechalSettings); |
| 383 |
|
| 384 |
if (vaStatus != VA_STATUS_SUCCESS) |
| 385 |
{ |
| 386 |
DdiEncodeCleanUp(encCtx); |
| 387 |
return vaStatus; |
| 388 |
} |
| 389 |
|
| 390 |
MOS_STATUS eStatus = pCodecHal->Allocate(encCtx->m_encode->m_codechalSettings); |
| 391 |
|
| 392 |
PMOS_INTERFACE osInterface = pCodecHal->GetOsInterface(); |
| 393 |
if (osInterface != nullptr && |
| 394 |
!osInterface->apoMosEnabled && |
| 395 |
MEDIA_IS_SKU(osInterface->pfnGetSkuTable(osInterface), FtrMemoryCompression) && |
| 396 |
!mediaDrvCtx->pMediaMemDecompState) |
| 397 |
{ |
| 398 |
mediaDrvCtx->pMediaMemDecompState = |
| 399 |
static_cast<MediaMemDecompState*>(MmdDevice::CreateFactory(&mosCtx)); |
| 400 |
} |
| 401 |
|
| 402 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 403 |
{ |
| 404 |
vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; |
| 405 |
DdiEncodeCleanUp(encCtx); |
| 406 |
return vaStatus; |
| 407 |
} |
| 408 |
|
| 409 |
vaStatus = encCtx->m_encode->InitCompBuffer(); |
| 410 |
if (vaStatus != VA_STATUS_SUCCESS) |
| 411 |
{ |
| 412 |
vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; |
| 413 |
DdiEncodeCleanUp(encCtx); |
| 414 |
return vaStatus; |
| 415 |
} |
| 416 |
|
| 417 |
// register the render target surfaces for this encoder instance |
| 418 |
// This is a must as driver has the constraint, 127 surfaces per context |
| 419 |
for (int32_t i = 0; i < num_render_targets; i++) |
| 420 |
{ |
| 421 |
DDI_MEDIA_SURFACE *surface; |
| 422 |
|
| 423 |
surface = DdiMedia_GetSurfaceFromVASurfaceID(mediaDrvCtx, render_targets[i]); |
| 424 |
if (nullptr == surface) |
| 425 |
{ |
| 426 |
DDI_ASSERTMESSAGE("DDI: invalid render target %d in vpgEncodeCreateContext.", i); |
| 427 |
vaStatus = VA_STATUS_ERROR_INVALID_SURFACE; |
| 428 |
DdiEncodeCleanUp(encCtx); |
| 429 |
return vaStatus; |
| 430 |
} |
| 431 |
encCtx->RTtbl.pRT[i] = surface; |
| 432 |
encCtx->RTtbl.iNumRenderTargets++; |
| 433 |
} |
| 434 |
|
| 435 |
// convert PDDI_ENCODE_CONTEXT to VAContextID |
| 436 |
DdiMediaUtil_LockMutex(&mediaDrvCtx->EncoderMutex); |
| 437 |
PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT vaContextHeapElmt = DdiMediaUtil_AllocPVAContextFromHeap(mediaDrvCtx->pEncoderCtxHeap); |
| 438 |
if (nullptr == vaContextHeapElmt) |
| 439 |
{ |
| 440 |
DdiMediaUtil_UnLockMutex(&mediaDrvCtx->EncoderMutex); |
| 441 |
vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED; |
| 442 |
DdiEncodeCleanUp(encCtx); |
| 443 |
return vaStatus; |
| 444 |
} |
| 445 |
|
| 446 |
vaContextHeapElmt->pVaContext = (void*)encCtx; |
| 447 |
mediaDrvCtx->uiNumEncoders++; |
| 448 |
*context = (VAContextID)(vaContextHeapElmt->uiVaContextID + DDI_MEDIA_VACONTEXTID_OFFSET_ENCODER); |
| 449 |
DdiMediaUtil_UnLockMutex(&mediaDrvCtx->EncoderMutex); |
| 450 |
|
| 451 |
return vaStatus; |
| 452 |
} |
| 453 |
|
| 454 |
/* |
| 455 |
* vaDestroyContext - Destroy a context |
| 456 |
* dpy: display |
| 457 |
* context: context to be destroyed |
| 458 |
*/ |
| 459 |
VAStatus DdiEncode_DestroyContext(VADriverContextP ctx, VAContextID context) |
| 460 |
{ |
| 461 |
DDI_CHK_NULL(ctx, "nullptr ctx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 462 |
DDI_CHK_NULL(ctx->pDriverData, "nullptr ctx->pDriverData", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 463 |
|
| 464 |
PDDI_MEDIA_CONTEXT mediaCtx = DdiMedia_GetMediaContext(ctx); |
| 465 |
DDI_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 466 |
|
| 467 |
// assume the VAContextID is encoder ID |
| 468 |
PDDI_ENCODE_CONTEXT encCtx = DdiEncode_GetEncContextFromContextID(ctx, context); |
| 469 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 470 |
DDI_CHK_NULL(encCtx->pCodecHal, "nullptr encCtx->pCodecHal", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 471 |
|
| 472 |
Codechal *codecHal = encCtx->pCodecHal; |
| 473 |
|
| 474 |
if (nullptr != encCtx->m_encode) |
| 475 |
{ |
| 476 |
encCtx->m_encode->FreeCompBuffer(); |
| 477 |
if(nullptr != encCtx->m_encode->m_codechalSettings) |
| 478 |
{ |
| 479 |
MOS_Delete(encCtx->m_encode->m_codechalSettings); |
| 480 |
encCtx->m_encode->m_codechalSettings = nullptr; |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
if (codecHal->GetOsInterface() && codecHal->GetOsInterface()->pOsContext) |
| 485 |
{ |
| 486 |
MOS_FreeMemory(codecHal->GetOsInterface()->pOsContext->pPerfData); |
| 487 |
codecHal->GetOsInterface()->pOsContext->pPerfData = nullptr; |
| 488 |
} |
| 489 |
|
| 490 |
// destroy codechal |
| 491 |
codecHal->Destroy(); |
| 492 |
MOS_Delete(codecHal); |
| 493 |
|
| 494 |
if (encCtx->pCpDdiInterface) |
| 495 |
{ |
| 496 |
Delete_DdiCpInterface(encCtx->pCpDdiInterface); |
| 497 |
encCtx->pCpDdiInterface = nullptr; |
| 498 |
} |
| 499 |
|
| 500 |
if (nullptr != encCtx->m_encode) |
| 501 |
{ |
| 502 |
MOS_Delete(encCtx->m_encode); |
| 503 |
encCtx->m_encode = nullptr; |
| 504 |
} |
| 505 |
|
| 506 |
MOS_FreeMemory(encCtx); |
| 507 |
encCtx = nullptr; |
| 508 |
|
| 509 |
uint32_t encIndex = (uint32_t)context; |
| 510 |
encIndex &= DDI_MEDIA_MASK_VACONTEXTID; |
| 511 |
|
| 512 |
DdiMediaUtil_LockMutex(&mediaCtx->EncoderMutex); |
| 513 |
DdiMediaUtil_ReleasePVAContextFromHeap(mediaCtx->pEncoderCtxHeap, encIndex); |
| 514 |
mediaCtx->uiNumEncoders--; |
| 515 |
DdiMediaUtil_UnLockMutex(&mediaCtx->EncoderMutex); |
| 516 |
|
| 517 |
return VA_STATUS_SUCCESS; |
| 518 |
} |
| 519 |
|
| 520 |
/* |
| 521 |
* Creates a buffer for "num_elements" elements of "size" bytes and |
| 522 |
* initalize with "data". |
| 523 |
* if "data" is null, then the contents of the buffer data store |
| 524 |
* are undefined. |
| 525 |
* Basically there are two ways to get buffer data to the server side. One is |
| 526 |
* to call vaCreateBuffer() with a non-null "data", which results the data being |
| 527 |
* copied to the data store on the server side. A different method that |
| 528 |
* eliminates this copy is to pass null as "data" when calling vaCreateBuffer(), |
| 529 |
* and then use vaMapBuffer() to map the data store from the server side to the |
| 530 |
* client address space for access. |
| 531 |
* Note: image buffers are created by the library, not the client. Please see |
| 532 |
* vaCreateImage on how image buffers are managed. |
| 533 |
*/ |
| 534 |
|
| 535 |
VAStatus DdiEncode_CreateBuffer( |
| 536 |
VADriverContextP ctx, |
| 537 |
VAContextID context, |
| 538 |
VABufferType type, |
| 539 |
uint32_t size, |
| 540 |
uint32_t num_elements, |
| 541 |
void *data, |
| 542 |
VABufferID *buf_id) |
| 543 |
{ |
| 544 |
DDI_CHK_NULL(ctx, "nullptr context!", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 545 |
|
| 546 |
DDI_ENCODE_CONTEXT *encCtx = DdiEncode_GetEncContextFromContextID(ctx, context); |
| 547 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 548 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 549 |
|
| 550 |
VAStatus vaStatus = encCtx->m_encode->CreateBuffer(ctx, type, size, num_elements, data, buf_id); |
| 551 |
|
| 552 |
return vaStatus; |
| 553 |
} |
| 554 |
|
| 555 |
/* |
| 556 |
* Get ready to encode a picture |
| 557 |
*/ |
| 558 |
VAStatus DdiEncode_BeginPicture( |
| 559 |
VADriverContextP ctx, |
| 560 |
VAContextID context, |
| 561 |
VASurfaceID render_target) |
| 562 |
{ |
| 563 |
PERF_UTILITY_AUTO(__FUNCTION__, PERF_ENCODE, PERF_LEVEL_DDI); |
| 564 |
|
| 565 |
DDI_FUNCTION_ENTER(); |
| 566 |
|
| 567 |
DDI_CHK_NULL(ctx, "nullptr context in vpgEncodeBeginPicture!", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 568 |
|
| 569 |
// assume the VAContextID is encoder ID |
| 570 |
PDDI_ENCODE_CONTEXT encCtx = DdiEncode_GetEncContextFromContextID(ctx, context); |
| 571 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 572 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 573 |
|
| 574 |
VAStatus vaStatus = encCtx->m_encode->BeginPicture(ctx, context, render_target); |
| 575 |
DDI_FUNCTION_EXIT(vaStatus); |
| 576 |
return vaStatus; |
| 577 |
} |
| 578 |
|
| 579 |
/* |
| 580 |
* Send encode buffers to the server. |
| 581 |
* Buffers are automatically destroyed afterwards |
| 582 |
*/ |
| 583 |
VAStatus DdiEncode_RenderPicture( |
| 584 |
VADriverContextP ctx, |
| 585 |
VAContextID context, |
| 586 |
VABufferID *buffers, |
| 587 |
int32_t num_buffers) |
| 588 |
{ |
| 589 |
VAStatus vaStatus = VA_STATUS_SUCCESS; |
| 590 |
int32_t numOfBuffers = num_buffers; |
| 591 |
int32_t priority = 0; |
| 592 |
int32_t priorityIndexInBuffers = -1; |
| 593 |
bool updatePriority = false; |
| 594 |
|
| 595 |
PERF_UTILITY_AUTO(__FUNCTION__, PERF_ENCODE, PERF_LEVEL_DDI); |
| 596 |
|
| 597 |
DDI_FUNCTION_ENTER(); |
| 598 |
|
| 599 |
DDI_CHK_NULL(ctx, "nullptr context in vpgEncodeRenderPicture!", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 600 |
|
| 601 |
// assume the VAContextID is encoder ID |
| 602 |
PDDI_ENCODE_CONTEXT encCtx = DdiEncode_GetEncContextFromContextID(ctx, context); |
| 603 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 604 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 605 |
|
| 606 |
priorityIndexInBuffers = DdiMedia_GetGpuPriority(ctx, buffers, numOfBuffers, &updatePriority, &priority); |
| 607 |
if (priorityIndexInBuffers != -1) |
| 608 |
{ |
| 609 |
if(updatePriority) |
| 610 |
{ |
| 611 |
vaStatus = DdiEncode_SetGpuPriority(encCtx, priority); |
| 612 |
if(vaStatus != VA_STATUS_SUCCESS) |
| 613 |
return vaStatus; |
| 614 |
} |
| 615 |
MovePriorityBufferIdToEnd(buffers, priorityIndexInBuffers, numOfBuffers); |
| 616 |
numOfBuffers--; |
| 617 |
} |
| 618 |
if (numOfBuffers == 0) |
| 619 |
return vaStatus; |
| 620 |
|
| 621 |
vaStatus = encCtx->m_encode->RenderPicture(ctx, context, buffers, numOfBuffers); |
| 622 |
DDI_FUNCTION_EXIT(vaStatus); |
| 623 |
return vaStatus; |
| 624 |
} |
| 625 |
|
| 626 |
VAStatus DdiEncode_EndPicture(VADriverContextP ctx, VAContextID context) |
| 627 |
{ |
| 628 |
PERF_UTILITY_AUTO(__FUNCTION__, PERF_ENCODE, PERF_LEVEL_DDI); |
| 629 |
|
| 630 |
DDI_FUNCTION_ENTER(); |
| 631 |
|
| 632 |
DDI_CHK_NULL(ctx, "nullptr context in vpgEncodeEndPicture!", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 633 |
|
| 634 |
// assume the VAContextID is encoder ID |
| 635 |
PDDI_ENCODE_CONTEXT encCtx = DdiEncode_GetEncContextFromContextID(ctx, context); |
| 636 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 637 |
DDI_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 638 |
|
| 639 |
VAStatus vaStatus = encCtx->m_encode->EndPicture(ctx, context); |
| 640 |
DDI_FUNCTION_EXIT(vaStatus); |
| 641 |
return vaStatus; |
| 642 |
} |
| 643 |
|
| 644 |
VAStatus DdiEncode_MfeSubmit( |
| 645 |
VADriverContextP ctx, |
| 646 |
VAMFContextID mfe_context, |
| 647 |
VAContextID *contexts, |
| 648 |
int32_t num_contexts |
| 649 |
) |
| 650 |
{ |
| 651 |
PDDI_MEDIA_CONTEXT mediaCtx = DdiMedia_GetMediaContext(ctx); |
| 652 |
DDI_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 653 |
|
| 654 |
uint32_t ctxType = DDI_MEDIA_CONTEXT_TYPE_NONE; |
| 655 |
PDDI_ENCODE_MFE_CONTEXT encodeMfeContext = (PDDI_ENCODE_MFE_CONTEXT)DdiMedia_GetContextFromContextID(ctx, mfe_context, &ctxType); |
| 656 |
DDI_CHK_NULL(encodeMfeContext, "nullptr encodeMfeContext", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 657 |
|
| 658 |
std::vector<PDDI_ENCODE_CONTEXT> encodeContexts; |
| 659 |
PDDI_ENCODE_CONTEXT encodeContext = nullptr; |
| 660 |
int32_t validContextNumber = 0; |
| 661 |
// Set mfe encoder params for this submission |
| 662 |
for (int32_t i = 0; i < num_contexts; i++) |
| 663 |
{ |
| 664 |
encodeContext = DdiEncode_GetEncContextFromContextID(ctx, contexts[i]); |
| 665 |
DDI_CHK_NULL(encodeContext, "nullptr encodeContext", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 666 |
CodechalEncoderState *encoder = dynamic_cast<CodechalEncoderState *>(encodeContext->pCodecHal); |
| 667 |
DDI_CHK_NULL(encoder, "nullptr codechal encoder", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 668 |
|
| 669 |
if (!encoder->m_mfeEnabled || |
| 670 |
encoder->m_mfeEncodeSharedState != encodeMfeContext->mfeEncodeSharedState) |
| 671 |
{ |
| 672 |
return VA_STATUS_ERROR_INVALID_CONTEXT; |
| 673 |
} |
| 674 |
|
| 675 |
// make sure the context has called BeginPicture&RenderPicture&EndPicture |
| 676 |
if (encodeContext->RTtbl.pRT[0] == nullptr |
| 677 |
|| encodeContext->dwNumSlices <= 0 |
| 678 |
|| encodeContext->EncodeParams.pBSBuffer != encodeContext->pbsBuffer) |
| 679 |
{ |
| 680 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 681 |
} |
| 682 |
|
| 683 |
encoder->m_mfeEncodeParams.submitIndex = i; |
| 684 |
encoder->m_mfeEncodeParams.submitNumber = num_contexts; |
| 685 |
encodeContexts.push_back(encodeContext); |
| 686 |
validContextNumber++; |
| 687 |
} |
| 688 |
|
| 689 |
CmDevice *device = encodeMfeContext->mfeEncodeSharedState->pCmDev; |
| 690 |
CmTask *task = encodeMfeContext->mfeEncodeSharedState->pCmTask; |
| 691 |
CmQueue *queue = encodeMfeContext->mfeEncodeSharedState->pCmQueue; |
| 692 |
CodechalEncodeMdfKernelResource *resMbencKernel = encodeMfeContext->mfeEncodeSharedState->resMbencKernel; |
| 693 |
SurfaceIndex *vmeSurface = encodeMfeContext->mfeEncodeSharedState->vmeSurface; |
| 694 |
SurfaceIndex *commonSurface = encodeMfeContext->mfeEncodeSharedState->commonSurface; |
| 695 |
|
| 696 |
|
| 697 |
MOS_ZeroMemory(encodeMfeContext->mfeEncodeSharedState, sizeof(MfeSharedState)); |
| 698 |
|
| 699 |
encodeMfeContext->mfeEncodeSharedState->pCmDev = device; |
| 700 |
encodeMfeContext->mfeEncodeSharedState->pCmTask = task; |
| 701 |
encodeMfeContext->mfeEncodeSharedState->pCmQueue = queue; |
| 702 |
encodeMfeContext->mfeEncodeSharedState->resMbencKernel = resMbencKernel; |
| 703 |
encodeMfeContext->mfeEncodeSharedState->vmeSurface = vmeSurface; |
| 704 |
encodeMfeContext->mfeEncodeSharedState->commonSurface = commonSurface; |
| 705 |
|
| 706 |
encodeMfeContext->mfeEncodeSharedState->encoders.clear(); |
| 707 |
|
| 708 |
// Call Enc functions for all the sub contexts |
| 709 |
MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 710 |
for (int32_t i = 0; i < validContextNumber; i++) |
| 711 |
{ |
| 712 |
encodeContext = encodeContexts[i]; |
| 713 |
if (encodeContext->vaEntrypoint != VAEntrypointFEI ) |
| 714 |
{ |
| 715 |
encodeContext->EncodeParams.ExecCodecFunction = CODECHAL_FUNCTION_ENC; |
| 716 |
} |
| 717 |
else |
| 718 |
{ |
| 719 |
encodeContext->EncodeParams.ExecCodecFunction = CODECHAL_FUNCTION_FEI_ENC; |
| 720 |
} |
| 721 |
|
| 722 |
CodechalEncoderState *encoder = dynamic_cast<CodechalEncoderState *>(encodeContext->pCodecHal); |
| 723 |
DDI_CHK_NULL(encoder, "nullptr encoder", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 724 |
|
| 725 |
encodeMfeContext->mfeEncodeSharedState->encoders.push_back(encoder); |
| 726 |
|
| 727 |
status = encoder->Execute(&encodeContext->EncodeParams); |
| 728 |
if (MOS_STATUS_SUCCESS != status) |
| 729 |
{ |
| 730 |
DDI_ASSERTMESSAGE("DDI:Failed in Execute Enc!"); |
| 731 |
return VA_STATUS_ERROR_ENCODING_ERROR; |
| 732 |
} |
| 733 |
} |
| 734 |
|
| 735 |
// Call Pak functions for all the sub contexts |
| 736 |
for (int32_t i = 0; i < validContextNumber; i++) |
| 737 |
{ |
| 738 |
encodeContext = encodeContexts[i]; |
| 739 |
if (encodeContext->vaEntrypoint != VAEntrypointFEI ) |
| 740 |
{ |
| 741 |
encodeContext->EncodeParams.ExecCodecFunction = CODECHAL_FUNCTION_PAK; |
| 742 |
} |
| 743 |
else |
| 744 |
{ |
| 745 |
encodeContext->EncodeParams.ExecCodecFunction = CODECHAL_FUNCTION_FEI_PAK; |
| 746 |
} |
| 747 |
|
| 748 |
CodechalEncoderState *encoder = dynamic_cast<CodechalEncoderState *>(encodeContext->pCodecHal); |
| 749 |
DDI_CHK_NULL(encoder, "nullptr encoder", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 750 |
|
| 751 |
status = encoder->Execute(&encodeContext->EncodeParams); |
| 752 |
if (MOS_STATUS_SUCCESS != status) |
| 753 |
{ |
| 754 |
DDI_ASSERTMESSAGE("DDI:Failed in Execute Pak!"); |
| 755 |
return VA_STATUS_ERROR_ENCODING_ERROR; |
| 756 |
} |
| 757 |
} |
| 758 |
|
| 759 |
return VA_STATUS_SUCCESS; |
| 760 |
} |
| 761 |
|
| 762 |
VAStatus DdiEncode_SetGpuPriority( |
| 763 |
PDDI_ENCODE_CONTEXT encCtx, |
| 764 |
int32_t priority |
| 765 |
) |
| 766 |
{ |
| 767 |
DDI_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 768 |
|
| 769 |
if(encCtx->pCodecHal != nullptr) |
| 770 |
{ |
| 771 |
PMOS_INTERFACE osInterface = encCtx->pCodecHal->GetOsInterface(); |
| 772 |
DDI_CHK_NULL(osInterface, "nullptr osInterface.", VA_STATUS_ERROR_ALLOCATION_FAILED); |
| 773 |
|
| 774 |
//Set Gpu priority for encoder |
| 775 |
osInterface->pfnSetGpuPriority(osInterface, priority); |
| 776 |
|
| 777 |
//Get the CMRT osInterface of encode |
| 778 |
CodechalEncoderState *encoder = dynamic_cast<CodechalEncoderState *>(encCtx->pCodecHal); |
| 779 |
DDI_CHK_NULL(encoder, "nullptr encoder", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 780 |
|
| 781 |
if(encoder->m_cmDev != nullptr) |
| 782 |
{ |
| 783 |
//Set Gpu priority for CMRT OsInterface |
| 784 |
CmDeviceRTBase *cm_device = dynamic_cast<CmDeviceRTBase *>(encoder->m_cmDev); |
| 785 |
DDI_CHK_NULL(cm_device, "nullptr cm_device", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 786 |
|
| 787 |
PCM_HAL_STATE cm_hal_state = cm_device->GetHalState(); |
| 788 |
if(cm_hal_state->osInterface != nullptr) |
| 789 |
cm_hal_state->osInterface->pfnSetGpuPriority(cm_hal_state->osInterface, priority); |
| 790 |
} |
| 791 |
} |
| 792 |
|
| 793 |
return VA_STATUS_SUCCESS; |
| 794 |
} |
| 795 |
|