1 /*
2 * Copyright (c) 2009-2019, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file media_libva_common.h
24 //! \brief libva(and its extension) interface implemantation common head file
25 //! \details libva(and its extension) interface implemantation common head file
26 //!
27
28 #ifndef __MEDIA_LIBVA_COMMON_H__
29 #define __MEDIA_LIBVA_COMMON_H__
30
31 #include <pthread.h>
32
33 #include "xf86drm.h"
34 #include "drm.h"
35 #include "i915_drm.h"
36 #include "mos_bufmgr.h"
37 #include "mos_context.h"
38 #include "mos_gpucontextmgr.h"
39 #include "mos_cmdbufmgr.h"
40
41 #include "mos_context_next.h"
42 #include "mos_gpucontextmgr_next.h"
43 #include "mos_cmdbufmgr_next.h"
44
45 #include "mos_os.h"
46 #include "mos_auxtable_mgr.h"
47
48 #ifdef _MANUAL_SOFTLET_
49 #include "ddi_media_functions.h"
50 #include "media_interfaces_hwinfo.h"
51 #endif
52
53 #include <va/va.h>
54 #include <va/va_backend.h>
55 #include <va/va_backend_vpp.h>
56 #include <va/va_drmcommon.h>
57 #include <va/va_dec_jpeg.h>
58 #include <va/va_backend.h>
59
60 #ifdef ANDROID
61 #include <utils/Log.h>
62
63 #ifndef LOG_TAG
64 #define LOG_TAG "DDI"
65 #endif
66 #if ANDROID_VERSION > 439 && defined(ENABLE_ATRACE)
67 #ifndef HAVE_ANDROID_OS
68 #define HAVE_ANDROID_OS
69 #endif
70 #define ATRACE_TAG (ATRACE_TAG_VIDEO | ATRACE_TAG_HAL)
71 #include <cutils/trace.h>
72 #define UMD_ATRACE_BEGIN(name) \
73 { \
74 if(atrace_switch) ATRACE_BEGIN(name); \
75 }
76 #define UMD_ATRACE_END \
77 { \
78 if(atrace_switch) ATRACE_END(); \
79 }
80 #include <cutils/properties.h>
81 static int32_t atrace_switch = 0;
82 #else
83 #define UMD_ATRACE_BEGIN __noop
84 #define UMD_ATRACE_END __noop
85 #endif
86 #else
87 #define UMD_ATRACE_BEGIN __noop
88 #define UMD_ATRACE_END __noop
89 #endif
90
91 #define DDI_UNUSED(param) MOS_UNUSED(param)
92
93 #define DDI_MEDIA_MAX_SURFACE_NUMBER_CONTEXT 127
94 #define DDI_MEDIA_MAX_INSTANCE_NUMBER 0x0FFFFFFF
95
96 // heap
97 #define DDI_MEDIA_HEAP_INCREMENTAL_SIZE 8
98
99 #define DDI_MEDIA_VACONTEXTID_OFFSET_DECODER 0x10000000
100 #define DDI_MEDIA_VACONTEXTID_OFFSET_ENCODER 0x20000000
101 #define DDI_MEDIA_VACONTEXTID_OFFSET_PROT 0x30000000
102 #define DDI_MEDIA_VACONTEXTID_OFFSET_VP 0x40000000
103 #define DDI_MEDIA_VACONTEXTID_OFFSET_MFE 0x70000000
104 #define DDI_MEDIA_VACONTEXTID_OFFSET_CM 0x80000000
105 #define DDI_MEDIA_MASK_VACONTEXT_TYPE 0xF0000000
106
107 #define DDI_MEDIA_MASK_VACONTEXTID 0x0FFFFFFF
108 #define DDI_MEDIA_CONTEXT_TYPE_DECODER 1
109 #define DDI_MEDIA_CONTEXT_TYPE_ENCODER 2
110 #define DDI_MEDIA_CONTEXT_TYPE_VP 3
111 #define DDI_MEDIA_CONTEXT_TYPE_MEDIA 4
112 #define DDI_MEDIA_CONTEXT_TYPE_CM 5
113 #define DDI_MEDIA_CONTEXT_TYPE_PROTECTED 6
114 #define DDI_MEDIA_CONTEXT_TYPE_MFE 7
115 #define DDI_MEDIA_CONTEXT_TYPE_NONE 0
116
117 #define DDI_MEDIA_INVALID_VACONTEXTID 0
118
119 #define DDI_MEDIA_MAX_COLOR_PLANES 4 //Maximum color planes supported by media driver, like (A/R/G/B in different planes)
120
121 typedef pthread_mutex_t MEDIA_MUTEX_T, *PMEDIA_MUTEX_T;
122 #define MEDIA_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
123
124 typedef sem_t MEDIA_SEM_T, *PMEDIA_SEM_T;
125
126 #ifndef VA_FOURCC_ABGR
127 #define VA_FOURCC_ABGR VA_FOURCC('A', 'B', 'G', 'R')
128 #endif
129
130 #ifndef VA_FOURCC_R5G6B5
131 #define VA_FOURCC_R5G6B5 VA_FOURCC('R','G','1', '6')
132 #endif
133
134 #ifndef VA_FOURCC_R8G8B8
135 #define VA_FOURCC_R8G8B8 VA_FOURCC('R','G','2', '4')
136 #endif
137
138 #ifndef VA_FOURCC_I420
139 #define VA_FOURCC_I420 VA_FOURCC('I','4','2', '0')
140 #endif
141
142 #define RGB_10BIT_ALPHAMASK VA_RT_FORMAT_RGB32_10BPP
143 #define RGB_8BIT_ALPHAMASK 0
144
145 #define MEDIAAPI_EXPORT __attribute__((visibility("default")))
146
147 class MediaLibvaCaps;
148 class MediaLibvaCapsNext;
149
150 typedef enum _DDI_MEDIA_FORMAT
151 {
152 Media_Format_NV12 ,
153 Media_Format_NV21 ,
154 Media_Format_Buffer ,
155 Media_Format_2DBuffer ,
156 Media_Format_Perf_Buffer ,
157 Media_Format_X8R8G8B8 ,
158 Media_Format_A8R8G8B8 ,
159 Media_Format_X8B8G8R8 ,
160 Media_Format_A8B8G8R8 ,
161 Media_Format_R8G8B8A8 ,
162 Media_Format_R5G6B5 ,
163 Media_Format_R10G10B10A2 ,
164 Media_Format_B10G10R10A2 ,
165 Media_Format_R10G10B10X2 ,
166 Media_Format_B10G10R10X2 ,
167 Media_Format_CPU ,
168
169 Media_Format_YUY2 ,
170 Media_Format_UYVY ,
171 Media_Format_YV12 ,
172 Media_Format_IYUV ,
173 Media_Format_I420 ,
174
175 Media_Format_422H ,
176 Media_Format_444P ,
177 Media_Format_411P ,
178 Media_Format_400P ,
179 Media_Format_422V ,
180 Media_Format_IMC3 ,
181
182 Media_Format_P010 ,
183 Media_Format_R8G8B8 ,
184 Media_Format_RGBP ,
185 Media_Format_BGRP ,
186
187 Media_Format_P016 ,
188 Media_Format_Y210 ,
189 Media_Format_Y216 ,
190 Media_Format_AYUV ,
191 #if VA_CHECK_VERSION(1, 13, 0)
192 Media_Format_XYUV ,
193 #endif
194 Media_Format_Y410 ,
195 Media_Format_Y416 ,
196 Media_Format_Y8 ,
197 Media_Format_Y16S ,
198 Media_Format_Y16U ,
199 Media_Format_VYUY ,
200 Media_Format_YVYU ,
201 Media_Format_A16R16G16B16,
202 Media_Format_A16B16G16R16,
203 Media_Format_P012 ,
204 #if VA_CHECK_VERSION(1, 9, 0)
205 Media_Format_Y212 ,
206 Media_Format_Y412 ,
207 #endif
208 Media_Format_Count
209 } DDI_MEDIA_FORMAT;
210
211 typedef enum _DDI_MEDIA_STATUS_REPORT_QUERY_STATE
212 {
213 DDI_MEDIA_STATUS_REPORT_QUERY_STATE_INIT,
214 DDI_MEDIA_STATUS_REPORT_QUERY_STATE_PENDING,
215 DDI_MEDIA_STATUS_REPORT_QUERY_STATE_COMPLETED,
216 DDI_MEDIA_STATUS_REPORT_QUERY_STATE_RELEASED
217 } DDI_MEDIA_STATUS_REPORT_QUERY_STATE;
218
219 //!
220 //! \brief Surface descriptor for external DRM buffer
221 //!
222 typedef struct _DDI_MEDIA_SURFACE_DESCRIPTOR
223 {
224 uint32_t uiPlanes; // brief number of planes for planar layout
225 uint32_t uiPitches[DDI_MEDIA_MAX_COLOR_PLANES]; // pitch for each plane in bytes
226 uint32_t uiOffsets[DDI_MEDIA_MAX_COLOR_PLANES]; // offset for each plane in bytes
227 uintptr_t ulBuffer; // buffer handle or user pointer
228 uint32_t uiSize; // buffer size
229 uint32_t uiFlags; // See "Surface external buffer descriptor flags"
230 uint32_t uiVaMemType; // VA Mem type
231 uint32_t uiTile; // Used for user pointer
232 uint32_t uiBuffserSize; // Used for user pointer
233 bool bIsGralloc; // buffer allocated by Gralloc
234 void *pPrivateData; // brief reserved for passing private data
235 GMM_RESCREATE_PARAMS GmmParam; // GMM Params for Gralloc buffer
236 uint64_t modifier; // used for VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2
237 } DDI_MEDIA_SURFACE_DESCRIPTOR,*PDDI_MEDIA_SURFACE_DESCRIPTOR;
238
239 //!
240 //! \struct DDI_MEDIA_CONTEXT
241 //! \brief Ddi media context
242 //!
243 struct DDI_MEDIA_CONTEXT;
244
245 typedef struct DDI_MEDIA_CONTEXT *PDDI_MEDIA_CONTEXT;
246
247 typedef union _DDI_MEDIA_SURFACE_STATUS_REPORT
248 {
249 //!
250 //! \struct _DDI_MEDIA_SURFACE_DECODE_STATUS
251 //! \brief Ddi media surface decode status
252 //!
253 struct _DDI_MEDIA_SURFACE_DECODE_STATUS
254 {
255 uint32_t status; // indicate latest decode status for current surface, refer to CODECHAL_STATUS in CodechalDecodeStatusReport.
256 uint32_t errMbNum; // indicate number of MB s with decode error, refer to NumMbsAffected in CodechalDecodeStatusReport
257 uint32_t crcValue; // indicate the CRC value of the decoded data
258 } decode;
259 //!
260 //! \struct _DDI_MEDIA_SURFACE_CENC_STATUS
261 //! \brief Ddi media surface cenc status
262 //!
263 struct _DDI_MEDIA_SURFACE_CENC_STATUS
264 {
265 uint32_t status; // indicate latest cenc status for current surface, refer to CODECHAL_STATUS in CodechalDecodeStatusReport.
266 uint32_t reserved; // reserved
267 } cenc;
268 //!
269 //! \struct _DDI_MEDIA_SURFACE_VPP_STATUS
270 //! \brief Ddi media surface vpp status
271 //!
272 struct _DDI_MEDIA_SURFACE_VPP_STATUS
273 {
274 uint32_t status; // indicate latest vpp status for current surface.
275 uint32_t reserved; // reserved.
276 } vpp;
277 } DDI_MEDIA_SURFACE_STATUS_REPORT, *PDDI_MEDIA_SURFACE_STATUS_REPORT;
278
279 struct _DDI_MEDIA_BUFFER;
280 typedef struct _DDI_MEDIA_SURFACE
281 {
282 // for hwcomposer, remove this after we have a solution
283 uint32_t base;
284 int32_t iWidth;
285 int32_t iHeight; // allocate height after alignment
286 int32_t iRealHeight; // real height before alignment
287 int32_t iPitch;
288 uint32_t uiOffset;
289 DDI_MEDIA_FORMAT format;
290 uint32_t uiLockedBufID;
291 uint32_t uiLockedImageID;
292 int32_t iRefCount;
293 uint8_t *pData;
294 uint32_t data_size;
295 uint32_t isTiled;
296 uint32_t TileType;
297 uint32_t bMapped;
298 MOS_LINUX_BO *bo;
299 uint32_t name;
300 uint32_t surfaceUsageHint;
301 PDDI_MEDIA_SURFACE_DESCRIPTOR pSurfDesc; // nullptr means surface was allocated by media driver
302 // !nullptr means surface was allocated by Application
303 GMM_RESOURCE_INFO *pGmmResourceInfo; // GMM resource descriptor
304 uint32_t frame_idx;
305 void *pDecCtx;
306 void *pVpCtx;
307
308 uint32_t curCtxType; // indicate current surface is using in which context type.
309 DDI_MEDIA_STATUS_REPORT_QUERY_STATE curStatusReportQueryState; // indicate status report is queried or not.
310 DDI_MEDIA_SURFACE_STATUS_REPORT curStatusReport; // union for both decode and vpp status.
311
312 PDDI_MEDIA_CONTEXT pMediaCtx; // Media driver Context
313 PMEDIA_SEM_T pCurrentFrameSemaphore; // to sync render target for hybrid decoding multi-threading mode
314 PMEDIA_SEM_T pReferenceFrameSemaphore; // to sync reference frame surface. when this semaphore is posted, the surface is not used as reference frame, and safe to be destroied
315
316 uint8_t *pSystemShadow; // Shadow surface in system memory
317 _DDI_MEDIA_BUFFER *pShadowBuffer;
318
319 uint32_t uiMapFlag;
320
321 uint32_t uiVariantFlag;
322 int memType;
323 } DDI_MEDIA_SURFACE, *PDDI_MEDIA_SURFACE;
324
325 typedef struct _DDI_MEDIA_BUFFER
326 {
327 uint32_t iSize;
328 uint32_t uiWidth;
329 uint32_t uiHeight;
330 uint32_t uiPitch;
331 uint32_t uiNumElements;
332 uint32_t uiOffset;
333 // vaBuffer type
334 uint32_t uiType;
335 DDI_MEDIA_FORMAT format;
336 uint32_t uiLockedBufID;
337 uint32_t uiLockedImageID;
338 int32_t iRefCount;
339 uint32_t TileType;
340 uint8_t *pData;
341 uint32_t bMapped;
342 MOS_LINUX_BO *bo;
343 uint32_t name;
344 uint32_t uiMemtype;
345 uint32_t uiExportcount;
346 uintptr_t handle;
347 bool bPostponedBufFree;
348
349 bool bCFlushReq; // No LLC between CPU & GPU, requries to call CPU Flush for CPU mapped buffer
350 bool bUseSysGfxMem;
351 PDDI_MEDIA_SURFACE pSurface;
352 GMM_RESOURCE_INFO *pGmmResourceInfo; // GMM resource descriptor
353 PDDI_MEDIA_CONTEXT pMediaCtx; // Media driver Context
354 } DDI_MEDIA_BUFFER, *PDDI_MEDIA_BUFFER;
355
356 typedef struct _DDI_MEDIA_SURFACE_HEAP_ELEMENT
357 {
358 PDDI_MEDIA_SURFACE pSurface;
359 uint32_t uiVaSurfaceID;
360 struct _DDI_MEDIA_SURFACE_HEAP_ELEMENT *pNextFree;
361 }DDI_MEDIA_SURFACE_HEAP_ELEMENT, *PDDI_MEDIA_SURFACE_HEAP_ELEMENT;
362
363 typedef struct _DDI_MEDIA_BUFFER_HEAP_ELEMENT
364 {
365 PDDI_MEDIA_BUFFER pBuffer;
366 void *pCtx;
367 uint32_t uiCtxType;
368 uint32_t uiVaBufferID;
369 struct _DDI_MEDIA_BUFFER_HEAP_ELEMENT *pNextFree;
370 }DDI_MEDIA_BUFFER_HEAP_ELEMENT, *PDDI_MEDIA_BUFFER_HEAP_ELEMENT;
371
372 typedef struct _DDI_MEDIA_IMAGE_HEAP_ELEMENT
373 {
374 VAImage *pImage;
375 uint32_t uiVaImageID;
376 struct _DDI_MEDIA_IMAGE_HEAP_ELEMENT *pNextFree;
377 }DDI_MEDIA_IMAGE_HEAP_ELEMENT, *PDDI_MEDIA_IMAGE_HEAP_ELEMENT;
378
379 typedef struct _DDI_MEDIA_VACONTEXT_HEAP_ELEMENT
380 {
381 void *pVaContext;
382 uint32_t uiVaContextID;
383 struct _DDI_MEDIA_VACONTEXT_HEAP_ELEMENT *pNextFree;
384 }DDI_MEDIA_VACONTEXT_HEAP_ELEMENT, *PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT;
385
386 typedef struct _DDI_MEDIA_HEAP
387 {
388 void *pHeapBase;
389 uint32_t uiHeapElementSize;
390 uint32_t uiAllocatedHeapElements;
391 void *pFirstFreeHeapElement;
392 }DDI_MEDIA_HEAP, *PDDI_MEDIA_HEAP;
393
394 #ifndef ANDROID
395 typedef struct _DDI_X11_FUNC_TABLE
396 {
397 HMODULE pX11LibHandle; // handle to dlopen libX11
398
399 // 5 functions from libX11 used by vpgPutSurface (Linux) so far
400 void *pfnDefaultVisual;
401 void *pfnXCreateGC;
402 void *pfnXFreeGC;
403 void *pfnXCreateImage;
404 void *pfnXDestroyImage;
405 void *pfnXPutImage;
406 }DDI_X11_FUNC_TABLE, *PDDI_X11_FUNC_TABLE;
407 #endif
408
409 //!
410 //! \struct DDI_MEDIA_CONTEXT
411 //! \brief Media heap for shared internal structures
412 //!
413 struct DDI_MEDIA_CONTEXT
414 {
415 MOS_BUFMGR *pDrmBufMgr;
416 // handle for /dev/dri/card0
417 int32_t fd;
418 int32_t iDeviceId;
419 bool bIsAtomSOC;
420
421 MEDIA_FEATURE_TABLE SkuTable;
422 MEDIA_WA_TABLE WaTable;
423
424 PDDI_MEDIA_HEAP pSurfaceHeap;
425 uint32_t uiNumSurfaces;
426
427 PDDI_MEDIA_HEAP pBufferHeap;
428 uint32_t uiNumBufs;
429
430 PDDI_MEDIA_HEAP pImageHeap;
431 uint32_t uiNumImages;
432
433 PDDI_MEDIA_HEAP pDecoderCtxHeap;
434 uint32_t uiNumDecoders;
435
436 PDDI_MEDIA_HEAP pEncoderCtxHeap;
437 uint32_t uiNumEncoders;
438
439 PDDI_MEDIA_HEAP pVpCtxHeap;
440 uint32_t uiNumVPs;
441
442 PDDI_MEDIA_HEAP pProtCtxHeap;
443 uint32_t uiNumProts;
444
445 PDDI_MEDIA_HEAP pCmCtxHeap;
446 uint32_t uiNumCMs;
447
448 PDDI_MEDIA_HEAP pMfeCtxHeap;
449 uint32_t uiNumMfes;
450
451 // display info
452 uint32_t uiDisplayWidth;
453 uint32_t uiDisplayHeight;
454
455 // media context reference number
456 uint32_t uiRef;
457
458 // modulized Gpu context and cmd buffer
459 bool modularizedGpuCtxEnabled;
460 OsContext *m_osContext;
461 GpuContextMgr *m_gpuContextMgr;
462 CmdBufMgr *m_cmdBufMgr;
463
464 // Apogeio MOS module
465 MOS_DEVICE_HANDLE m_osDeviceContext = MOS_INVALID_HANDLE;
466
467 // mutexs to protect the shared resource among multiple context
468 MEDIA_MUTEX_T SurfaceMutex;
469 MEDIA_MUTEX_T MemDecompMutex;
470 MEDIA_MUTEX_T BufferMutex;
471 MEDIA_MUTEX_T ImageMutex;
472 MEDIA_MUTEX_T DecoderMutex;
473 MEDIA_MUTEX_T EncoderMutex;
474 MEDIA_MUTEX_T VpMutex;
475 MEDIA_MUTEX_T ProtMutex;
476 MEDIA_MUTEX_T CmMutex;
477 MEDIA_MUTEX_T MfeMutex;
478
479 // GT system Info
480 MEDIA_SYSTEM_INFO *pGtSystemInfo;
481
482 // Media memory decompression data structure
483 void *pMediaMemDecompState;
484
485 // Media copy data structure
486 void *pMediaCopyState;
487
488 // Perf tag
489 PERF_DATA *perfData;
490
491 // Media reset enable flag
492 bool bMediaResetEnable;
493
494 // Media memory decompression function
495 void (* pfnMemoryDecompress)(
496 PMOS_CONTEXT pMosCtx,
497 PMOS_RESOURCE pOsResource);
498
499 //!
500 //! \brief the function ptr for surface copy function
501 //!
502 void (* pfnMediaMemoryCopy )(
503 PMOS_CONTEXT pMosCtx,
504 PMOS_RESOURCE pInputResource,
505 PMOS_RESOURCE pOutputResource,
506 bool bOutputCompressed);
507
508 //!
509 //! \brief the function ptr for Media Memory 2D copy function
510 //!
511 void (* pfnMediaMemoryCopy2D)(
512 PMOS_CONTEXT pMosCtx,
513 PMOS_RESOURCE pInputResource,
514 PMOS_RESOURCE pOutputResource,
515 uint32_t copyWidth,
516 uint32_t copyHeight,
517 uint32_t copyInputOffset,
518 uint32_t copyOutputOffset,
519 uint32_t bpp,
520 bool bOutputCompressed);
521
522 //!
523 //! \brief the function ptr for Media Tile Convert function
524 //!
525 VAStatus (* pfnMediaMemoryTileConvert)(
526 PMOS_CONTEXT pMosCtx,
527 PMOS_RESOURCE pInputResource,
528 PMOS_RESOURCE pOutputResource,
529 uint32_t copyWidth,
530 uint32_t copyHeight,
531 uint32_t copyInputOffset,
532 uint32_t copyOutputOffset,
533 bool isTileToLinear,
534 bool outputCompressed);
535
536 PLATFORM platform;
537
538 MediaLibvaCaps *m_caps;
539
540 GMM_CLIENT_CONTEXT *pGmmClientContext;
541
542 // Aux Table Manager
543 AuxTableMgr *m_auxTableMgr;
544
545 bool m_useSwSwizzling;
546 bool m_tileYFlag;
547
548 #if !defined(ANDROID) && defined(X11_FOUND)
549 // X11 Func table, for vpgPutSurface (Linux)
550 PDDI_X11_FUNC_TABLE X11FuncTable;
551
552 /* VA/DRI (X11) specific data */
553 struct va_dri_output *dri_output;
554 //vpgPutSurfaceLinuxHW acceleration hack
555 MEDIA_MUTEX_T PutSurfaceRenderMutex;
556 MEDIA_MUTEX_T PutSurfaceSwapBufferMutex;
557 #endif
558 bool m_apoMosEnabled;
559 #ifdef _MANUAL_SOFTLET_
560 DdiMediaFunctions *m_compList[CompCount] = {nullptr};
561 MediaInterfacesHwInfo *m_hwInfo = nullptr;
562 MediaLibvaCapsNext *m_capsNext = nullptr;
563 #endif
564 };
565
DdiMedia_GetMediaContext(VADriverContextP ctx)566 static __inline PDDI_MEDIA_CONTEXT DdiMedia_GetMediaContext (VADriverContextP ctx)
567 {
568 return (PDDI_MEDIA_CONTEXT)ctx->pDriverData;
569 }
570
571 //!
572 //! \brief Media surface to mos resource
573 //!
574 //! \param [in] mediaSurface
575 //! Ddi media surface
576 //! \param [in] mhalOsResource
577 //! Mos resource
578 //!
579 void DdiMedia_MediaSurfaceToMosResource(DDI_MEDIA_SURFACE *mediaSurface, MOS_RESOURCE *mhalOsResource);
580
581 //!
582 //! \brief Media buffer to mos resource
583 //!
584 //! \param [in] mediaBuffer
585 //! Ddi media buffer
586 //! \param [in] mhalOsResource
587 //! Mos resource
588 //!
589 void DdiMedia_MediaBufferToMosResource(DDI_MEDIA_BUFFER *mediaBuffer, MOS_RESOURCE *mhalOsResource);
590
591 //!
592 //! \brief Get context from context ID
593 //!
594 //! \param [in] ctx
595 //! Pointer to VA driver context
596 //! \param [in] vaCtxID
597 //! VA context ID
598 //! \param [in] ctxType
599 //! Ctx type
600 //!
601 void* DdiMedia_GetContextFromContextID (VADriverContextP ctx, VAContextID vaCtxID, uint32_t *ctxType);
602
603 //!
604 //! \brief Get surface from VA surface ID
605 //!
606 //! \param [in] mediaCtx
607 //! Pointer to ddi media context
608 //! \param [in] surfaceID
609 //! VA surface ID
610 //!
611 //! \return DDI_MEDIA_SURFACE*
612 //! Pointer to ddi media surface
613 //!
614 DDI_MEDIA_SURFACE* DdiMedia_GetSurfaceFromVASurfaceID (PDDI_MEDIA_CONTEXT mediaCtx, VASurfaceID surfaceID);
615
616 //!
617 //! \brief replace the surface with given format
618 //!
619 //! \param [in] surface
620 //! Pointer to the old surface
621 //! \param [in] expectedFormat
622 //! VA surface ID
623 //!
624 //! \return DDI_MEDIA_SURFACE*
625 //! Pointer to new ddi media surface
626 //!
627 PDDI_MEDIA_SURFACE DdiMedia_ReplaceSurfaceWithNewFormat(PDDI_MEDIA_SURFACE surface, DDI_MEDIA_FORMAT expectedFormat);
628
629 //!
630 //! \brief replace the surface with correlation variant format
631 //!
632 //! \param [in] surface
633 //! Pointer to the old surface
634 //!
635 //! \return DDI_MEDIA_SURFACE*
636 //! Pointer to new ddi media surface
637 //!
638 PDDI_MEDIA_SURFACE DdiMedia_ReplaceSurfaceWithVariant(PDDI_MEDIA_SURFACE surface, VAEntrypoint entrypoint);
639
640 //!
641 //! \brief Get VA surface ID from surface
642 //!
643 //! \param [in] surface
644 //! surface
645 //!
646 //! \return VASurfaceID
647 //! VA Surface ID
648 //!
649 VASurfaceID DdiMedia_GetVASurfaceIDFromSurface(PDDI_MEDIA_SURFACE surface);
650
651 //!
652 //! \brief Get buffer from VA buffer ID
653 //!
654 //! \param [in] mediaCtx
655 //! Pointer to ddi media context
656 //! \param [in] bufferID
657 //! VA buffer ID
658 //!
659 //! \return DDI_MEDIA_BUFFER*
660 //! Pointer to ddi media buffer
661 //!
662 DDI_MEDIA_BUFFER* DdiMedia_GetBufferFromVABufferID (PDDI_MEDIA_CONTEXT mediaCtx, VABufferID bufferID);
663
664 //!
665 //! \brief Get context from VA buffer ID
666 //!
667 //! \param [in] mediaCtx
668 //! Pointer to ddi media context
669 //! \param [in] bufferID
670 //! VA buffer ID
671 //!
672 //! \return void*
673 //! Pointer to context
674 //!
675 void* DdiMedia_GetContextFromVABufferID (PDDI_MEDIA_CONTEXT mediaCtx, VABufferID bufferID);
676
677 //!
678 //! \brief Destroy buffer from VA buffer ID
679 //!
680 //! \param [in] mediaCtx
681 //! Pointer to ddi media context
682 //! \param [in] bufferID
683 //! VA buffer ID
684 //!
685 //! \return bool
686 //! true if destroy buffer from VA buffer ID, else false
687 //!
688 bool DdiMedia_DestroyBufFromVABufferID (PDDI_MEDIA_CONTEXT mediaCtx, VABufferID bufferID);
689
690 //!
691 //! \brief Get gpu priority
692 //!
693 //! \param [in] ctx
694 //! Pointer to VA driver context
695 //! \param [in] buffers
696 //! VA buffer ID
697 //! \param [in] numBuffers
698 //! Number of buffers
699 //! \param [out] updatePriority
700 //! Update priority
701 //! \param [out] priority
702 //! Priority value
703 //! \return int32_t
704 //!
705 int32_t DdiMedia_GetGpuPriority (VADriverContextP ctx, VABufferID *buffers, int32_t numBuffers, bool *updatePriority, int32_t *priority);
706
707 //!
708 //! \brief Move a bufferID to the end of buffers
709 //!
710 //! \param [in,out] buffers
711 //! VA buffer ID
712 //! \param [in] priorityIndexInBuf
713 //! Location of priority buffer
714 //! \param [in] numBuffers
715 //! Number of buffers
716 //! \return void
717 //!
718 void MovePriorityBufferIdToEnd (VABufferID *buffers, int32_t priorityIndexInBuf, int32_t numBuffers);
719
720 #endif
721