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