Debian Codegraph @

media_softlet/linux/common/codec/ddi/enc/ddi_encode_functions.cpp

raw
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_encode_functions.cpp
24 //! \brief ddi encode functions implementaion.
25 //!
26 #include "ddi_encode_functions.h"
27 #include "media_libva_common_next.h"
28 #include "ddi_encode_hevc_specific.h"
29 #include "ddi_register_components_specific.h"
30 #include "codechal_memdecomp.h"
31 #include "media_interfaces_codechal_next.h"
32 #include "media_interfaces_mmd.h"
33 #include "media_libva_interface_next.h"
34
35 VAStatus DdiEncodeFunctions::CreateConfig (
36 VADriverContextP ctx,
37 VAProfile profile,
38 VAEntrypoint entrypoint,
39 VAConfigAttrib *attribList,
40 int32_t numAttribs,
41 VAConfigID *configId)
42 {
43 VAStatus status = VA_STATUS_SUCCESS;
44 DDI_CODEC_CHK_NULL(configId, "nullptr configId", VA_STATUS_ERROR_INVALID_PARAMETER);
45
46 PDDI_MEDIA_CONTEXT mediaCtx = GetMediaContext(ctx);
47 DDI_CODEC_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
48 DDI_CODEC_CHK_NULL(mediaCtx->m_capsNext, "nullptr m_caps", VA_STATUS_ERROR_INVALID_PARAMETER);
49 DDI_CODEC_CHK_NULL(mediaCtx->m_capsNext->m_capsTable, "nullptr m_capsTable", VA_STATUS_ERROR_INVALID_PARAMETER);
50
51 status = mediaCtx->m_capsNext->CreateConfig(profile, entrypoint, attribList, numAttribs, configId);
52 DDI_CODEC_CHK_RET(status, "Create common config failed");
53
54 uint32_t rcMode = VA_RC_CQP;
55 uint32_t feiFunction = 0;
56
57 if((entrypoint == VAEntrypointStats) || (entrypoint == VAEntrypointEncPicture))
58 {
59 rcMode = VA_RC_NONE;
60 }
61
62 for(int i = 0; i < numAttribs; i++)
63 {
64 if(attribList[i].type == VAConfigAttribFEIFunctionType)
65 {
66 feiFunction = attribList[i].value;
67 }
68
69 if(attribList[i].type == VAConfigAttribRateControl && attribList[i].value != VA_RC_MB)
70 {
71 rcMode = attribList[i].value;
72 }
73 }
74
75 auto configList = mediaCtx->m_capsNext->GetConfigList();
76 DDI_CODEC_CHK_NULL(configList, "Get configList failed", VA_STATUS_ERROR_INVALID_PARAMETER);
77
78 for(int i = 0; i < configList->size(); i++)
79 {
80 if((configList->at(i).profile == profile) &&
81 (configList->at(i).entrypoint == entrypoint))
82 {
83 if((rcMode == configList->at(i).componentData.data.rcMode) &&
84 (feiFunction == configList->at(i).componentData.data.feiFunction))
85 {
86 uint32_t curConfigID = ADD_CONFIG_ID_ENC_OFFSET(i);
87 if(!mediaCtx->m_capsNext->m_capsTable->IsEncConfigId(curConfigID))
88 {
89 DDI_CODEC_ASSERTMESSAGE("DDI: Invalid configID.");
90 return VA_STATUS_ERROR_INVALID_CONFIG;
91 }
92
93 *configId = curConfigID;
94 return VA_STATUS_SUCCESS;
95 }
96 }
97 }
98
99 *configId = 0xFFFFFFFF;
100 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
101 }
102
103 VAStatus DdiEncodeFunctions::CreateContext (
104 VADriverContextP ctx,
105 VAConfigID configId,
106 int32_t pictureWidth,
107 int32_t pictureHeight,
108 int32_t flag,
109 VASurfaceID *renderTargets,
110 int32_t renderTargetsNum,
111 VAContextID *context)
112 {
113 PERF_UTILITY_AUTO(__FUNCTION__, PERF_ENCODE, PERF_LEVEL_DDI);
114
115 DDI_CODEC_CHK_NULL(ctx, "nullptr ctx", VA_STATUS_ERROR_INVALID_CONTEXT);
116 DDI_CODEC_CHK_NULL(ctx->pDriverData, "nullptr ctx->pDriverData", VA_STATUS_ERROR_INVALID_CONTEXT);
117
118 PDDI_MEDIA_CONTEXT mediaCtx = GetMediaContext(ctx);
119 DDI_CODEC_CHK_NULL(mediaCtx->m_capsNext, "nullptr m_capsNext", VA_STATUS_ERROR_INVALID_CONTEXT);
120 DDI_CODEC_CHK_NULL(mediaCtx->m_capsNext->m_capsTable, "nullptr m_capsTable", VA_STATUS_ERROR_INVALID_CONTEXT);
121
122 ConfigLinux* configItem = nullptr;
123 configItem = mediaCtx->m_capsNext->m_capsTable->QueryConfigItemFromIndex(configId);
124 DDI_CODEC_CHK_NULL(configItem, "Invalid config id!", VA_STATUS_ERROR_INVALID_PARAMETER);
125
126 if (renderTargetsNum > DDI_MEDIA_MAX_SURFACE_NUMBER_CONTEXT)
127 {
128 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
129 }
130
131 encode::DdiEncodeBase *ddiEncode = DdiEncodeFactory::Create(ComponentInfo{configItem->profile, configItem->entrypoint});
132 DDI_CODEC_CHK_NULL(ddiEncode, "nullptr ddiEncode", VA_STATUS_ERROR_UNIMPLEMENTED);
133 VAStatus vaStatus = ddiEncode->CheckEncodeResolution(
134 mediaCtx->m_capsNext,
135 configId,
136 pictureWidth,
137 pictureHeight);
138 if (vaStatus != VA_STATUS_SUCCESS)
139 {
140 return VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
141 }
142
143 // first create encoder context
144 ddiEncode->m_encodeCtx = (decltype(ddiEncode->m_encodeCtx))MOS_AllocAndZeroMemory(sizeof(encode::DDI_ENCODE_CONTEXT));
145 DDI_CODEC_CHK_NULL(ddiEncode->m_encodeCtx, "nullptr ddiEncode->m_encodeCtx", VA_STATUS_ERROR_ALLOCATION_FAILED);
146 DDI_CODEC_VERBOSEMESSAGE(" DdiEncodeFunctions::CreateContext encCtx %p ddiEncode %p", ddiEncode->m_encodeCtx, ddiEncode);
147
148 encode::PDDI_ENCODE_CONTEXT encCtx = ddiEncode->m_encodeCtx;
149 encCtx->m_encode = ddiEncode;
150
151 //initialize DDI level cp interface
152 MOS_CONTEXT mosCtx = {};
153 encCtx->pCpDdiInterfaceNext = CreateDdiCpNext(&mosCtx);
154 if (nullptr == encCtx->pCpDdiInterfaceNext)
155 {
156 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
157 CleanUp(encCtx);
158 return vaStatus;
159 }
160
161 // Get the buf manager for codechal create
162 mosCtx.bufmgr = mediaCtx->pDrmBufMgr;
163 mosCtx.fd = mediaCtx->fd;
164 mosCtx.iDeviceId = mediaCtx->iDeviceId;
165 mosCtx.m_skuTable = mediaCtx->SkuTable;
166 mosCtx.m_waTable = mediaCtx->WaTable;
167 mosCtx.m_gtSystemInfo = *mediaCtx->pGtSystemInfo;
168 mosCtx.m_platform = mediaCtx->platform;
169
170 mosCtx.ppMediaMemDecompState = &mediaCtx->pMediaMemDecompState;
171 mosCtx.pfnMemoryDecompress = mediaCtx->pfnMemoryDecompress;
172 mosCtx.pfnMediaMemoryCopy = mediaCtx->pfnMediaMemoryCopy;
173 mosCtx.pfnMediaMemoryCopy2D = mediaCtx->pfnMediaMemoryCopy2D;
174 mosCtx.ppMediaCopyState = &mediaCtx->pMediaCopyState;
175 mosCtx.m_gtSystemInfo = *mediaCtx->pGtSystemInfo;
176 mosCtx.m_auxTableMgr = mediaCtx->m_auxTableMgr;
177 mosCtx.pGmmClientContext = mediaCtx->pGmmClientContext;
178
179 mosCtx.m_osDeviceContext = mediaCtx->m_osDeviceContext;
180 mosCtx.m_apoMosEnabled = true;
181 mosCtx.m_userSettingPtr = mediaCtx->m_userSettingPtr;
182
183 mosCtx.pPerfData = (PERF_DATA *)MOS_AllocAndZeroMemory(sizeof(PERF_DATA));
184 if (nullptr == mosCtx.pPerfData)
185 {
186 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
187 CleanUp(encCtx);
188 return vaStatus;
189 }
190
191 if (configItem->entrypoint == VAEntrypointEncSlice)
192 {
193 encCtx->bVdencActive = true;
194 }
195
196 encCtx->vaEntrypoint = configItem->entrypoint;
197 encCtx->vaProfile = configItem->profile;
198 encCtx->uiRCMethod = configItem->componentData.data.rcMode;
199 encCtx->wModeType = ddiEncode->GetEncodeCodecMode(configItem->profile, configItem->entrypoint);
200 encCtx->codecFunction = ddiEncode->GetEncodeCodecFunction(configItem->profile, configItem->entrypoint, encCtx->bVdencActive);
201
202 CODECHAL_STANDARD_INFO standardInfo;
203 MOS_ZeroMemory(&standardInfo, sizeof(CODECHAL_STANDARD_INFO));
204 standardInfo.CodecFunction = encCtx->codecFunction;
205 standardInfo.Mode = encCtx->wModeType;
206 Codechal *pCodecHal = CodechalDeviceNext::CreateFactory(
207 nullptr,
208 &mosCtx,
209 &standardInfo,
210 nullptr);
211 if (pCodecHal == nullptr)
212 {
213 // add anything necessary here to free the resource
214 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
215 CleanUp(encCtx);
216 return vaStatus;
217 }
218
219 encCtx->pCodecHal = pCodecHal;
220
221 // Setup some initial data
222 encCtx->dworiFrameWidth = pictureWidth;
223 encCtx->dworiFrameHeight = pictureHeight;
224 encCtx->wPicWidthInMB = (uint16_t)(DDI_CODEC_NUM_MACROBLOCKS_WIDTH(pictureWidth));
225 encCtx->wPicHeightInMB = (uint16_t)(DDI_CODEC_NUM_MACROBLOCKS_HEIGHT(pictureHeight));
226 encCtx->dwFrameWidth = encCtx->wPicWidthInMB * CODECHAL_MACROBLOCK_WIDTH;
227 encCtx->dwFrameHeight = encCtx->wPicHeightInMB * CODECHAL_MACROBLOCK_HEIGHT;
228 //recoder old resolution for dynamic resolution change
229 encCtx->wContextPicWidthInMB = encCtx->wPicWidthInMB;
230 encCtx->wContextPicHeightInMB = encCtx->wPicHeightInMB;
231 encCtx->wOriPicWidthInMB = encCtx->wPicWidthInMB;
232 encCtx->wOriPicHeightInMB = encCtx->wPicHeightInMB;
233 encCtx->targetUsage = TARGETUSAGE_RT_SPEED;
234 // Attach PMEDIDA_DRIVER_CONTEXT
235 encCtx->pMediaCtx = mediaCtx;
236
237 encCtx->pCpDdiInterfaceNext->SetCpFlags(flag);
238 encCtx->pCpDdiInterfaceNext->SetCpParams(CP_TYPE_NONE, encCtx->m_encode->m_codechalSettings);
239
240 vaStatus = encCtx->m_encode->ContextInitialize(encCtx->m_encode->m_codechalSettings);
241
242 if (vaStatus != VA_STATUS_SUCCESS)
243 {
244 CleanUp(encCtx);
245 return vaStatus;
246 }
247
248 MOS_STATUS eStatus = pCodecHal->Allocate(encCtx->m_encode->m_codechalSettings);
249
250 PMOS_INTERFACE osInterface = pCodecHal->GetOsInterface();
251 if (osInterface != nullptr &&
252 !osInterface->apoMosEnabled &&
253 MEDIA_IS_SKU(osInterface->pfnGetSkuTable(osInterface), FtrMemoryCompression) &&
254 !mediaCtx->pMediaMemDecompState)
255 {
256 mediaCtx->pMediaMemDecompState =
257 static_cast<MediaMemDecompState *>(MmdDevice::CreateFactory(&mosCtx));
258 }
259
260 if (eStatus != MOS_STATUS_SUCCESS)
261 {
262 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
263 CleanUp(encCtx);
264 return vaStatus;
265 }
266
267 vaStatus = encCtx->m_encode->InitCompBuffer();
268 if (vaStatus != VA_STATUS_SUCCESS)
269 {
270 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
271 CleanUp(encCtx);
272 return vaStatus;
273 }
274
275 // register the render target surfaces for this encoder instance
276 // This is a must as driver has the constraint, 127 surfaces per context
277 for (int32_t i = 0; i < renderTargetsNum; i++)
278 {
279 DDI_MEDIA_SURFACE *surface;
280
281 surface = MediaLibvaCommonNext::GetSurfaceFromVASurfaceID(mediaCtx, renderTargets[i]);
282 if (nullptr == surface)
283 {
284 DDI_CODEC_ASSERTMESSAGE("DDI: invalid render target %d in vpgEncodeCreateContext.", i);
285 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
286 CleanUp(encCtx);
287 return vaStatus;
288 }
289 encCtx->RTtbl.pRT[i] = surface;
290 encCtx->RTtbl.iNumRenderTargets++;
291 }
292
293 // convert PDDI_ENCODE_CONTEXT to VAContextID
294 MosUtilities::MosLockMutex(&mediaCtx->EncoderMutex);
295 PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT vaContextHeapElmt = MediaLibvaUtilNext::DdiAllocPVAContextFromHeap(mediaCtx->pEncoderCtxHeap);
296 if (nullptr == vaContextHeapElmt)
297 {
298 MosUtilities::MosUnlockMutex(&mediaCtx->EncoderMutex);
299 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
300 CleanUp(encCtx);
301 return vaStatus;
302 }
303
304 vaContextHeapElmt->pVaContext = (void *)encCtx;
305 mediaCtx->uiNumEncoders++;
306 *context = (VAContextID)(vaContextHeapElmt->uiVaContextID + DDI_MEDIA_SOFTLET_VACONTEXTID_ENCODER_OFFSET);
307 MosUtilities::MosUnlockMutex(&mediaCtx->EncoderMutex);
308 DDI_CODEC_VERBOSEMESSAGE(" DdiEncodeFunctions::CreateContext ctx %p *context %d", ctx, *context);
309 return vaStatus;
310 }
311
312 VAStatus DdiEncodeFunctions::DestroyContext (
313 VADriverContextP ctx,
314 VAContextID context)
315 {
316 DDI_CODEC_CHK_NULL(ctx, "nullptr ctx", VA_STATUS_ERROR_INVALID_CONTEXT);
317 DDI_CODEC_CHK_NULL(ctx->pDriverData, "nullptr ctx->pDriverData", VA_STATUS_ERROR_INVALID_CONTEXT);
318
319 PDDI_MEDIA_CONTEXT mediaCtx = GetMediaContext(ctx);
320 DDI_CODEC_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
321
322 // assume the VAContextID is encoder ID
323 uint32_t ctxType = 0;
324 encode::PDDI_ENCODE_CONTEXT encCtx = (decltype(encCtx))MediaLibvaCommonNext::GetContextFromContextID(ctx, context, &ctxType);
325 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
326 DDI_CODEC_CHK_NULL(encCtx->pCodecHal, "nullptr encCtx->pCodecHal", VA_STATUS_ERROR_INVALID_CONTEXT);
327
328 Codechal *codecHal = encCtx->pCodecHal;
329
330 if (nullptr != encCtx->m_encode)
331 {
332 encCtx->m_encode->FreeCompBuffer();
333 if(nullptr != encCtx->m_encode->m_codechalSettings)
334 {
335 MOS_Delete(encCtx->m_encode->m_codechalSettings);
336 encCtx->m_encode->m_codechalSettings = nullptr;
337 }
338 }
339
340 if (codecHal->GetOsInterface() && codecHal->GetOsInterface()->pOsContext)
341 {
342 MOS_FreeMemory(codecHal->GetOsInterface()->pOsContext->pPerfData);
343 codecHal->GetOsInterface()->pOsContext->pPerfData = nullptr;
344 }
345
346 // destroy codechal
347 codecHal->Destroy();
348 MOS_Delete(codecHal);
349
350 if (encCtx->pCpDdiInterfaceNext)
351 {
352 MOS_Delete(encCtx->pCpDdiInterfaceNext);
353 }
354
355 if (nullptr != encCtx->m_encode)
356 {
357 MOS_Delete(encCtx->m_encode);
358 encCtx->m_encode = nullptr;
359 }
360
361 MOS_FreeMemory(encCtx);
362 encCtx = nullptr;
363
364 uint32_t encIndex = (uint32_t)context;
365 encIndex &= DDI_MEDIA_MASK_VACONTEXTID;
366
367 MosUtilities::MosLockMutex(&mediaCtx->EncoderMutex);
368 MediaLibvaUtilNext::DdiReleasePVAContextFromHeap(mediaCtx->pEncoderCtxHeap, encIndex);
369 mediaCtx->uiNumEncoders--;
370 MosUtilities::MosUnlockMutex(&mediaCtx->EncoderMutex);
371 return VA_STATUS_SUCCESS;
372 }
373
374 VAStatus DdiEncodeFunctions::CreateBuffer (
375 VADriverContextP ctx,
376 VAContextID context,
377 VABufferType type,
378 uint32_t size,
379 uint32_t elementsNum,
380 void *data,
381 VABufferID *bufId)
382 {
383 DDI_CODEC_CHK_NULL(ctx, "nullptr context!", VA_STATUS_ERROR_INVALID_CONTEXT);
384
385 uint32_t ctxType = 0;
386 encode::PDDI_ENCODE_CONTEXT encCtx = (decltype(encCtx))MediaLibvaCommonNext::GetContextFromContextID(ctx, context, &ctxType);
387 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
388 DDI_CODEC_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT);
389
390 VAStatus vaStatus = encCtx->m_encode->CreateBuffer(ctx, type, size, elementsNum, data, bufId);
391
392 return VA_STATUS_SUCCESS;
393 }
394
395 VAStatus DdiEncodeFunctions::MapBufferInternal(
396 DDI_MEDIA_CONTEXT *mediaCtx,
397 VABufferID buf_id,
398 void **pbuf,
399 uint32_t flag
400 )
401 {
402 DDI_CODEC_FUNC_ENTER;
403 MOS_TraceEventExt(EVENT_VA_MAP, EVENT_TYPE_START, &buf_id, sizeof(buf_id), &flag, sizeof(flag));
404
405 DDI_CODEC_CHK_NULL(pbuf, "nullptr pbuf", VA_STATUS_ERROR_INVALID_PARAMETER);
406
407 DDI_CODEC_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
408
409 DDI_CODEC_CHK_NULL(mediaCtx->pBufferHeap, "nullptr mediaCtx->pBufferHeap", VA_STATUS_ERROR_INVALID_CONTEXT);
410 DDI_CODEC_CHK_LESS((uint32_t)buf_id, mediaCtx->pBufferHeap->uiAllocatedHeapElements, "Invalid bufferId", VA_STATUS_ERROR_INVALID_CONTEXT);
411
412 DDI_MEDIA_BUFFER *buf = MediaLibvaCommonNext::GetBufferFromVABufferID(mediaCtx, buf_id);
413 DDI_CODEC_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_BUFFER);
414
415 // The context is nullptr when the buffer is created from DeriveImage
416 // So doesn't need to check the context for all cases
417 // Only check the context in dec/enc mode
418 VAStatus vaStatus = VA_STATUS_SUCCESS;
419 uint32_t ctxType = MediaLibvaCommonNext::GetCtxTypeFromVABufferID(mediaCtx, buf_id);
420 void *ctxPtr = nullptr;
421 DDI_CODEC_COM_BUFFER_MGR *bufMgr = nullptr;
422 encode::PDDI_ENCODE_CONTEXT encCtx = nullptr;
423
424 ctxPtr = MediaLibvaCommonNext::GetCtxFromVABufferID(mediaCtx, buf_id);
425 DDI_CODEC_CHK_NULL(ctxPtr, "nullptr ctxPtr", VA_STATUS_ERROR_INVALID_CONTEXT);
426
427 encCtx = encode::GetEncContextFromPVOID(ctxPtr);
428 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
429 bufMgr = &(encCtx->BufMgr);
430
431 MOS_TraceEventExt(EVENT_VA_MAP, EVENT_TYPE_INFO, &ctxType, sizeof(ctxType), &buf->uiType, sizeof(uint32_t));
432 switch ((int32_t)buf->uiType)
433 {
434 case VAEncCodedBufferType:
435 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
436
437 if( CodedBufferExistInStatusReport( encCtx, buf ) )
438 {
439 vaStatus = StatusReport(encCtx, buf, pbuf);
440 MOS_TraceEventExt(EVENT_VA_MAP, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
441 return vaStatus;
442 }
443 // so far a coded buffer that has NOT been added into status report is skipped frame in non-CP case
444 // but this can change in future if new usage models come up
445 encCtx->BufMgr.pCodedBufferSegment->buf = MediaLibvaUtilNext::LockBuffer(buf, flag);
446 encCtx->BufMgr.pCodedBufferSegment->size = buf->iSize;
447 *pbuf = encCtx->BufMgr.pCodedBufferSegment;
448
449 break;
450
451 case VAStatsStatisticsBufferType:
452 case VAStatsStatisticsBottomFieldBufferType:
453 case VAStatsMVBufferType:
454 {
455 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT)
456 encode::DDI_ENCODE_PRE_ENC_BUFFER_TYPE idx = (buf->uiType == VAStatsMVBufferType) ? encode::PRE_ENC_BUFFER_TYPE_MVDATA :
457 ((buf->uiType == VAStatsStatisticsBufferType) ? encode::PRE_ENC_BUFFER_TYPE_STATS
458 : encode::PRE_ENC_BUFFER_TYPE_STATS_BOT);
459 if((encCtx->codecFunction == CODECHAL_FUNCTION_FEI_PRE_ENC) && PreEncBufferExistInStatusReport( encCtx, buf, idx))
460 {
461 vaStatus = PreEncStatusReport(encCtx, buf, pbuf);
462 MOS_TraceEventExt(EVENT_VA_MAP, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
463 return vaStatus;
464 }
465 if(buf->bo)
466 {
467 *pbuf = MediaLibvaUtilNext::LockBuffer(buf, flag);
468 }
469 break;
470 }
471 case VAStatsMVPredictorBufferType:
472 case VAEncFEIMBControlBufferType:
473 case VAEncFEIMVPredictorBufferType:
474 case VAEncQPBufferType:
475 if(buf->bo)
476 {
477 *pbuf = MediaLibvaUtilNext::LockBuffer(buf, flag);
478 }
479 break;
480 case VAEncFEIMVBufferType:
481 case VAEncFEIMBCodeBufferType:
482 case VAEncFEICURecordBufferType:
483 case VAEncFEICTBCmdBufferType:
484 case VAEncFEIDistortionBufferType:
485 {
486 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT)
487 if(encCtx->wModeType == CODECHAL_ENCODE_MODE_AVC)
488 {
489 CodecEncodeAvcFeiPicParams *feiPicParams = (CodecEncodeAvcFeiPicParams *)encCtx->pFeiPicParams;
490
491 encode::DDI_ENCODE_FEI_ENC_BUFFER_TYPE idx = (buf->uiType == VAEncFEIMVBufferType) ? encode::FEI_ENC_BUFFER_TYPE_MVDATA :
492 ((buf->uiType == VAEncFEIMBCodeBufferType) ? encode::FEI_ENC_BUFFER_TYPE_MBCODE :
493 encode::FEI_ENC_BUFFER_TYPE_DISTORTION);
494 if((feiPicParams != nullptr) && (encCtx->codecFunction == CODECHAL_FUNCTION_FEI_ENC) && EncBufferExistInStatusReport(encCtx, buf, idx))
495 {
496 vaStatus = EncStatusReport(encCtx, buf, pbuf);
497 MOS_TraceEventExt(EVENT_VA_MAP, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
498 return vaStatus;
499 }
500 }
501 else if(encCtx->wModeType == CODECHAL_ENCODE_MODE_HEVC)
502
503 {
504 CodecEncodeHevcFeiPicParams *feiPicParams = (CodecEncodeHevcFeiPicParams *)encCtx->pFeiPicParams;
505 encode::DDI_ENCODE_FEI_ENC_BUFFER_TYPE idx = (buf->uiType == VAEncFEICTBCmdBufferType) ? encode::FEI_ENC_BUFFER_TYPE_MVDATA :
506 ((buf->uiType == VAEncFEICURecordBufferType) ? encode::FEI_ENC_BUFFER_TYPE_MBCODE :
507 encode::FEI_ENC_BUFFER_TYPE_DISTORTION);
508 if((feiPicParams != nullptr) && (encCtx->codecFunction == CODECHAL_FUNCTION_FEI_ENC) && EncBufferExistInStatusReport( encCtx, buf, idx))
509 {
510 vaStatus = EncStatusReport(encCtx, buf, pbuf);
511 MOS_TraceEventExt(EVENT_VA_MAP, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
512 return vaStatus;
513 }
514 }
515 if(buf->bo)
516 {
517 *pbuf = MediaLibvaUtilNext::LockBuffer(buf, flag);
518 }
519 }
520 break;
521 case VAStatsStatisticsParameterBufferType:
522 *pbuf = (void *)(buf->pData + buf->uiOffset);
523 break;
524 case VAEncMacroblockMapBufferType:
525 MosUtilities::MosLockMutex(&mediaCtx->BufferMutex);
526 *pbuf = MediaLibvaUtilNext::LockBuffer(buf, flag);
527 MosUtilities::MosUnlockMutex(&mediaCtx->BufferMutex);
528 MOS_TraceEventExt(EVENT_VA_MAP, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
529 if (nullptr == (*pbuf))
530 {
531 return VA_STATUS_ERROR_OPERATION_FAILED;
532 }
533 else
534 {
535 return VA_STATUS_SUCCESS;
536 }
537 break;
538
539 case VAProbabilityBufferType:
540 *pbuf = (void *)(buf->pData + buf->uiOffset);
541
542 break;
543
544 case VAEncMacroblockDisableSkipMapBufferType:
545 if(buf->bo)
546 {
547 *pbuf = MediaLibvaUtilNext::LockBuffer(buf, flag);
548 }
549 break;
550
551 case VAImageBufferType:
552 default:
553 vaStatus = DdiMediaFunctions::MapBufferInternal(mediaCtx, buf_id, pbuf, MOS_LOCKFLAG_READONLY | MOS_LOCKFLAG_WRITEONLY);
554 break;
555 }
556
557 MOS_TraceEventExt(EVENT_VA_MAP, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
558 return vaStatus;
559 }
560
561 VAStatus DdiEncodeFunctions::UnmapBuffer (
562 DDI_MEDIA_CONTEXT *mediaCtx,
563 VABufferID buf_id
564 )
565 {
566 DDI_CODEC_FUNC_ENTER;
567 MOS_TraceEventExt(EVENT_VA_UNMAP, EVENT_TYPE_START, &buf_id, sizeof(buf_id), nullptr, 0);
568
569 DDI_CODEC_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
570
571 DDI_CODEC_CHK_NULL( mediaCtx->pBufferHeap, "nullptr mediaCtx->pBufferHeap", VA_STATUS_ERROR_INVALID_CONTEXT);
572 DDI_CODEC_CHK_LESS((uint32_t)buf_id, mediaCtx->pBufferHeap->uiAllocatedHeapElements, "Invalid buf_id", VA_STATUS_ERROR_INVALID_BUFFER);
573
574 DDI_MEDIA_BUFFER *buf = MediaLibvaCommonNext::GetBufferFromVABufferID(mediaCtx, buf_id);
575 DDI_CODEC_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_BUFFER);
576
577 // The context is nullptr when the buffer is created from DeriveImage
578 // So doesn't need to check the context for all cases
579 // Only check the context in enc mode
580 void *ctxPtr = nullptr;
581 uint32_t ctxType = MediaLibvaCommonNext::GetCtxTypeFromVABufferID(mediaCtx, buf_id);
582 DDI_CODEC_COM_BUFFER_MGR *bufMgr = nullptr;
583 encode::PDDI_ENCODE_CONTEXT encCtx = nullptr;
584
585 ctxPtr = MediaLibvaCommonNext::GetCtxFromVABufferID(mediaCtx, buf_id);
586 DDI_CODEC_CHK_NULL(ctxPtr, "nullptr ctxPtr", VA_STATUS_ERROR_INVALID_CONTEXT);
587
588 encCtx = encode::GetEncContextFromPVOID(ctxPtr);
589 bufMgr = &(encCtx->BufMgr);
590
591 switch ((int32_t)buf->uiType)
592 {
593 case VASliceDataBufferType:
594 case VAProtectedSliceDataBufferType:
595 case VABitPlaneBufferType:
596 break;
597 case VAEncCodedBufferType:
598 case VAStatsStatisticsBufferType:
599 case VAStatsStatisticsBottomFieldBufferType:
600 case VAStatsMVBufferType:
601 case VAStatsMVPredictorBufferType:
602 case VAEncFEIMBControlBufferType:
603 case VAEncFEIMVPredictorBufferType:
604 case VAEncFEIMVBufferType:
605 case VAEncFEIMBCodeBufferType:
606 case VAEncFEICURecordBufferType:
607 case VAEncFEICTBCmdBufferType:
608 case VAEncFEIDistortionBufferType:
609 case VAEncQPBufferType:
610 case VAEncMacroblockDisableSkipMapBufferType:
611 if(buf->bo)
612 {
613 MediaLibvaUtilNext::UnlockBuffer(buf);
614 }
615 break;
616
617 default:
618 DdiMediaFunctions::UnmapBuffer(mediaCtx, buf_id);
619 break;
620 }
621
622 MOS_TraceEventExt(EVENT_VA_UNMAP, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
623 return VA_STATUS_SUCCESS;
624 }
625
626 VAStatus DdiEncodeFunctions::DestroyBuffer (
627 DDI_MEDIA_CONTEXT *mediaCtx,
628 VABufferID buffer_id
629 )
630 {
631 DDI_CODEC_FUNC_ENTER;
632 MOS_TraceEventExt(EVENT_VA_FREE_BUFFER, EVENT_TYPE_START, &buffer_id, sizeof(buffer_id), nullptr, 0);
633
634 DDI_CODEC_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
635
636 DDI_CODEC_CHK_NULL(mediaCtx->pBufferHeap, "nullptr mediaCtx->pBufferHeap", VA_STATUS_ERROR_INVALID_CONTEXT);
637 DDI_CODEC_CHK_LESS((uint32_t)buffer_id, mediaCtx->pBufferHeap->uiAllocatedHeapElements, "Invalid bufferId", VA_STATUS_ERROR_INVALID_CONTEXT);
638
639 DDI_MEDIA_BUFFER *buf = MediaLibvaCommonNext::GetBufferFromVABufferID(mediaCtx, buffer_id);
640 DDI_CODEC_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_BUFFER);
641
642 void *ctxPtr = MediaLibvaCommonNext::GetCtxFromVABufferID(mediaCtx, buffer_id);
643 uint32_t ctxType = MediaLibvaCommonNext::GetCtxTypeFromVABufferID(mediaCtx, buffer_id);
644
645 DDI_CODEC_COM_BUFFER_MGR *bufMgr = nullptr;
646 encode::PDDI_ENCODE_CONTEXT encCtx = nullptr;
647
648 encCtx = encode::GetEncContextFromPVOID(ctxPtr);
649 bufMgr = &(encCtx->BufMgr);
650
651 switch ((int32_t)buf->uiType)
652 {
653 case VAImageBufferType:
654 if(buf->format == Media_Format_CPU)
655 {
656 MOS_DeleteArray(buf->pData);
657 }
658 else
659 {
660 MediaLibvaUtilNext::UnRefBufObjInMediaBuffer(buf);
661
662 if (buf->uiExportcount) {
663 buf->bPostponedBufFree = true;
664 MOS_TraceEventExt(EVENT_VA_FREE_BUFFER, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
665 return VA_STATUS_SUCCESS;
666 }
667 }
668 break;
669 case VAIQMatrixBufferType:
670 case VAHuffmanTableBufferType:
671 case VAEncSliceParameterBufferType:
672 case VAEncPictureParameterBufferType:
673 case VAEncSequenceParameterBufferType:
674 case VAEncPackedHeaderDataBufferType:
675 case VAEncPackedHeaderParameterBufferType:
676 MOS_DeleteArray(buf->pData);
677 break;
678 case VAEncMacroblockMapBufferType:
679 MediaLibvaUtilNext::FreeBuffer(buf);
680 break;
681 #ifdef ENABLE_ENC_UNLIMITED_OUTPUT
682 case VAEncCodedBufferType:
683 if(nullptr == encCtx)
684 {
685 encCtx = encode::GetEncContextFromPVOID(ctxPtr);
686 if(nullptr == encCtx)
687 return VA_STATUS_ERROR_INVALID_CONTEXT;
688 }
689 MediaLibvaUtilNext::FreeBuffer(buf);
690 break;
691 #endif
692 case VAStatsStatisticsParameterBufferType:
693 MOS_DeleteArray(buf->pData);
694 break;
695 case VAStatsStatisticsBufferType:
696 case VAStatsStatisticsBottomFieldBufferType:
697 case VAStatsMVBufferType:
698 {
699 if(nullptr == encCtx)
700 {
701 encCtx = encode::GetEncContextFromPVOID(ctxPtr);
702 if(nullptr == encCtx)
703 return VA_STATUS_ERROR_INVALID_CONTEXT;
704 }
705 if(encCtx->codecFunction == CODECHAL_FUNCTION_FEI_PRE_ENC)
706 {
707 encode::DDI_ENCODE_PRE_ENC_BUFFER_TYPE idx = (buf->uiType == VAStatsMVBufferType) ? encode::PRE_ENC_BUFFER_TYPE_MVDATA :
708 ((buf->uiType == VAStatsStatisticsBufferType) ? encode::PRE_ENC_BUFFER_TYPE_STATS
709 : encode::PRE_ENC_BUFFER_TYPE_STATS_BOT);
710 RemoveFromPreEncStatusReportQueue(encCtx, buf, idx);
711 }
712 }
713 MediaLibvaUtilNext::FreeBuffer(buf);
714 break;
715 case VAStatsMVPredictorBufferType:
716 case VAEncFEIMBControlBufferType:
717 case VAEncFEIMVPredictorBufferType:
718 case VAEncQPBufferType:
719 case VADecodeStreamoutBufferType:
720 MediaLibvaUtilNext::FreeBuffer(buf);
721 break;
722 case VAEncFEIMVBufferType:
723 case VAEncFEIMBCodeBufferType:
724 case VAEncFEICURecordBufferType:
725 case VAEncFEICTBCmdBufferType:
726 case VAEncFEIDistortionBufferType:
727 {
728 if(nullptr == encCtx)
729 {
730 encCtx = encode::GetEncContextFromPVOID(ctxPtr);
731 if(nullptr == encCtx)
732 return VA_STATUS_ERROR_INVALID_CONTEXT;
733 }
734 if(encCtx->wModeType == CODECHAL_ENCODE_MODE_AVC)
735 {
736 CodecEncodeAvcFeiPicParams *feiPicParams;
737 feiPicParams = (CodecEncodeAvcFeiPicParams *)(encCtx->pFeiPicParams);
738 if((feiPicParams != nullptr) && (encCtx->codecFunction == CODECHAL_FUNCTION_FEI_ENC))
739 {
740 encode::DDI_ENCODE_FEI_ENC_BUFFER_TYPE idx = (buf->uiType == VAEncFEIMVBufferType) ? encode::FEI_ENC_BUFFER_TYPE_MVDATA :
741 ((buf->uiType == VAEncFEIMBCodeBufferType) ? encode::FEI_ENC_BUFFER_TYPE_MBCODE :
742 encode::FEI_ENC_BUFFER_TYPE_DISTORTION);
743 RemoveFromEncStatusReportQueue(encCtx, buf, idx);
744 }
745
746 }
747 else if(encCtx->wModeType == CODECHAL_ENCODE_MODE_HEVC)
748 {
749 CodecEncodeHevcFeiPicParams *feiPicParams;
750 feiPicParams = (CodecEncodeHevcFeiPicParams *)(encCtx->pFeiPicParams);
751 if((feiPicParams != nullptr) && (encCtx->codecFunction == CODECHAL_FUNCTION_FEI_ENC))
752 {
753 encode::DDI_ENCODE_FEI_ENC_BUFFER_TYPE idx = (buf->uiType == VAEncFEICTBCmdBufferType) ? encode::FEI_ENC_BUFFER_TYPE_MVDATA :
754 ((buf->uiType == VAEncFEICURecordBufferType) ? encode::FEI_ENC_BUFFER_TYPE_MBCODE :
755 encode::FEI_ENC_BUFFER_TYPE_DISTORTION);
756 RemoveFromEncStatusReportQueue(encCtx, buf, idx);
757 }
758 }
759 }
760 MediaLibvaUtilNext::FreeBuffer(buf);
761 break;
762 default: // do not handle any un-listed buffer type
763 MOS_DeleteArray(buf->pData);
764 break;
765 //return va_STATUS_SUCCESS;
766 }
767 MOS_Delete(buf);
768
769 MediaLibvaInterfaceNext::DestroyBufFromVABufferID(mediaCtx, buffer_id);
770 MOS_TraceEventExt(EVENT_VA_FREE_BUFFER, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
771 return VA_STATUS_SUCCESS;
772 }
773
774 VAStatus DdiEncodeFunctions::BeginPicture (
775 VADriverContextP ctx,
776 VAContextID context,
777 VASurfaceID renderTarget)
778 {
779 PERF_UTILITY_AUTO(__FUNCTION__, PERF_ENCODE, PERF_LEVEL_DDI);
780 DDI_CODEC_FUNC_ENTER;
781
782 DDI_CODEC_CHK_NULL(ctx, "nullptr context in vpgEncodeBeginPicture!", VA_STATUS_ERROR_INVALID_CONTEXT);
783
784 // assume the VAContextID is encoder ID
785 uint32_t ctxType = 0;
786 encode::PDDI_ENCODE_CONTEXT encCtx = (decltype(encCtx))MediaLibvaCommonNext::GetContextFromContextID(ctx, context, &ctxType);
787 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
788 DDI_CODEC_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT);
789
790 VAStatus vaStatus = encCtx->m_encode->BeginPicture(ctx, context, renderTarget);
791 return vaStatus;
792 }
793
794 VAStatus DdiEncodeFunctions::RenderPicture (
795 VADriverContextP ctx,
796 VAContextID context,
797 VABufferID *buffers,
798 int32_t buffersNum)
799 {
800 VAStatus vaStatus = VA_STATUS_SUCCESS;
801 int32_t numOfBuffers = buffersNum;
802 int32_t priority = 0;
803 int32_t priorityIndexInBuffers = -1;
804 bool updatePriority = false;
805 PERF_UTILITY_AUTO(__FUNCTION__, PERF_ENCODE, PERF_LEVEL_DDI);
806 DDI_CODEC_FUNC_ENTER;
807
808 DDI_CODEC_CHK_NULL(ctx, "nullptr context in vpgEncodeRenderPicture!", VA_STATUS_ERROR_INVALID_CONTEXT);
809
810 // assume the VAContextID is encoder ID
811 uint32_t ctxType = 0;
812 encode::PDDI_ENCODE_CONTEXT encCtx = (decltype(encCtx))MediaLibvaCommonNext::GetContextFromContextID(ctx, context, &ctxType);
813 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
814 DDI_CODEC_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT);
815
816 priorityIndexInBuffers = MediaLibvaCommonNext::GetGpuPriority(ctx, buffers, numOfBuffers, &updatePriority, &priority);
817 if (priorityIndexInBuffers != -1)
818 {
819 if(updatePriority)
820 {
821 vaStatus = SetGpuPriority(encCtx, priority);
822 if(vaStatus != VA_STATUS_SUCCESS)
823 return vaStatus;
824 }
825 MediaLibvaCommonNext::MovePriorityBufferIdToEnd(buffers, priorityIndexInBuffers, numOfBuffers);
826 numOfBuffers--;
827 }
828 if (numOfBuffers == 0)
829 return vaStatus;
830
831 vaStatus = encCtx->m_encode->RenderPicture(ctx, context, buffers, numOfBuffers);
832 return vaStatus;
833 }
834
835 VAStatus DdiEncodeFunctions::EndPicture (
836 VADriverContextP ctx,
837 VAContextID context)
838 {
839 PERF_UTILITY_AUTO(__FUNCTION__, PERF_ENCODE, PERF_LEVEL_DDI);
840
841 DDI_CODEC_FUNC_ENTER;
842 DDI_CODEC_CHK_NULL(ctx, "nullptr context in vpgEncodeEndPicture!", VA_STATUS_ERROR_INVALID_CONTEXT);
843
844 // assume the VAContextID is encoder ID
845 uint32_t ctxType = 0;
846 encode::PDDI_ENCODE_CONTEXT encCtx = (decltype(encCtx))MediaLibvaCommonNext::GetContextFromContextID(ctx, context, &ctxType);
847 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
848 DDI_CODEC_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT);
849
850 VAStatus vaStatus = encCtx->m_encode->EndPicture(ctx, context);
851 return vaStatus;
852 }
853
854 //!
855 //! \brief Clean and free encode context structure
856 //!
857 //! \param [in] encCtx
858 //! Pointer to ddi encode context
859 //!
860 void DdiEncodeFunctions::CleanUp(encode::PDDI_ENCODE_CONTEXT encCtx)
861 {
862 if (encCtx->m_encode)
863 {
864 MOS_Delete(encCtx->m_encode);
865 encCtx->m_encode = nullptr;
866 }
867
868 if (encCtx->pCpDdiInterfaceNext)
869 {
870 MOS_Delete(encCtx->pCpDdiInterfaceNext);
871 }
872
873 MOS_FreeMemory(encCtx);
874 encCtx = nullptr;
875
876 return;
877 }
878
879 VAStatus DdiEncodeFunctions::SetGpuPriority(
880 encode::PDDI_ENCODE_CONTEXT encCtx,
881 int32_t priority
882 )
883 {
884 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
885
886 if(encCtx->pCodecHal != nullptr)
887 {
888 PMOS_INTERFACE osInterface = encCtx->pCodecHal->GetOsInterface();
889 DDI_CODEC_CHK_NULL(osInterface, "nullptr osInterface.", VA_STATUS_ERROR_ALLOCATION_FAILED);
890
891 //Set Gpu priority for encoder
892 osInterface->pfnSetGpuPriority(osInterface, priority);
893 }
894
895 return VA_STATUS_SUCCESS;
896 }
897
898 bool DdiEncodeFunctions::CodedBufferExistInStatusReport(
899 encode::PDDI_ENCODE_CONTEXT encCtx,
900 PDDI_MEDIA_BUFFER buf)
901 {
902 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
903 DDI_CODEC_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT);
904 DDI_CODEC_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER);
905
906 return encCtx->m_encode->CodedBufferExistInStatusReport(buf);
907 }
908
909 VAStatus DdiEncodeFunctions::StatusReport (
910 encode::PDDI_ENCODE_CONTEXT encCtx,
911 DDI_MEDIA_BUFFER *mediaBuf,
912 void **buf
913 )
914 {
915 PERF_UTILITY_AUTO(__FUNCTION__, PERF_ENCODE, PERF_LEVEL_DDI);
916
917 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
918 DDI_CODEC_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT);
919 DDI_CODEC_CHK_NULL(mediaBuf, "nullptr mediaBuf", VA_STATUS_ERROR_INVALID_PARAMETER);
920 DDI_CODEC_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER);
921
922 VAStatus vaStatus = encCtx->m_encode->StatusReport(mediaBuf, buf);
923
924 return vaStatus;
925 }
926
927 bool DdiEncodeFunctions::PreEncBufferExistInStatusReport(
928 encode::PDDI_ENCODE_CONTEXT encCtx,
929 PDDI_MEDIA_BUFFER buf,
930 encode:: DDI_ENCODE_PRE_ENC_BUFFER_TYPE typeIdx)
931 {
932 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
933 DDI_CODEC_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT);
934 DDI_CODEC_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER);
935
936 return encCtx->m_encode->PreEncBufferExistInStatusReport(buf, typeIdx);
937 }
938
939 VAStatus DdiEncodeFunctions::PreEncStatusReport(
940 encode::PDDI_ENCODE_CONTEXT encCtx,
941 DDI_MEDIA_BUFFER *mediaBuf,
942 void **buf)
943 {
944 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
945 DDI_CODEC_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT);
946 DDI_CODEC_CHK_NULL(mediaBuf, "nullptr mediaBuf", VA_STATUS_ERROR_INVALID_PARAMETER);
947 DDI_CODEC_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER);
948
949 VAStatus vaStatus = encCtx->m_encode->PreEncStatusReport(mediaBuf, buf);
950
951 return vaStatus;
952 }
953
954 bool DdiEncodeFunctions::EncBufferExistInStatusReport(
955 encode::PDDI_ENCODE_CONTEXT encCtx,
956 PDDI_MEDIA_BUFFER buf,
957 encode::DDI_ENCODE_FEI_ENC_BUFFER_TYPE typeIdx)
958 {
959 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
960 DDI_CODEC_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT);
961 DDI_CODEC_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER);
962
963 return encCtx->m_encode->EncBufferExistInStatusReport(buf, typeIdx);
964 }
965
966 VAStatus DdiEncodeFunctions::EncStatusReport(
967 encode::PDDI_ENCODE_CONTEXT encCtx,
968 DDI_MEDIA_BUFFER *mediaBuf,
969 void **buf)
970 {
971 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
972 DDI_CODEC_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT);
973 DDI_CODEC_CHK_NULL(mediaBuf, "nullptr mediaBuf", VA_STATUS_ERROR_INVALID_PARAMETER);
974 DDI_CODEC_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER);
975
976 VAStatus vaStatus = encCtx->m_encode->EncStatusReport(mediaBuf, buf);
977
978 return vaStatus;
979 }
980
981 VAStatus DdiEncodeFunctions::RemoveFromPreEncStatusReportQueue(
982 encode::PDDI_ENCODE_CONTEXT encCtx,
983 PDDI_MEDIA_BUFFER buf,
984 encode::DDI_ENCODE_PRE_ENC_BUFFER_TYPE typeIdx)
985 {
986 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
987 DDI_CODEC_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT);
988 DDI_CODEC_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER);
989
990 VAStatus vaStatus = encCtx->m_encode->RemoveFromPreEncStatusReportQueue(buf, typeIdx);
991
992 return vaStatus;
993 }
994
995 VAStatus DdiEncodeFunctions::RemoveFromEncStatusReportQueue(
996 encode::PDDI_ENCODE_CONTEXT encCtx,
997 PDDI_MEDIA_BUFFER buf,
998 encode::DDI_ENCODE_FEI_ENC_BUFFER_TYPE typeIdx)
999 {
1000 DDI_CODEC_CHK_NULL(encCtx, "nullptr encCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
1001 DDI_CODEC_CHK_NULL(encCtx->m_encode, "nullptr encCtx->m_encode", VA_STATUS_ERROR_INVALID_CONTEXT);
1002 DDI_CODEC_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER);
1003
1004 VAStatus vaStatus = encCtx->m_encode->RemoveFromEncStatusReportQueue(buf, typeIdx);
1005
1006 return vaStatus;
1007 }