Debian Codegraph @

media_driver/linux/common/ddi/media_libva_common.h

raw
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 "mos_context_next.h"
34 #include "mos_gpucontextmgr_next.h"
35 #include "mos_cmdbufmgr_next.h"
36
37 class CmdBufMgr;
38
39 #include "mos_os.h"
40 #include "mos_auxtable_mgr.h"
41
42 #include "ddi_media_functions.h"
43 #include "media_interfaces_hwinfo.h"
44
45 #include <va/va.h>
46 #include <va/va_backend.h>
47 #include <va/va_backend_vpp.h>
48 #include <va/va_drmcommon.h>
49 #include <va/va_dec_jpeg.h>
50 #include <va/va_backend.h>
51
52 #include "media_libva_common_next.h"
53 #ifdef ANDROID
54 #include <utils/Log.h>
55
56 #ifndef LOG_TAG
57 #define LOG_TAG "DDI"
58 #endif
59 #if ANDROID_VERSION > 439 && defined(ENABLE_ATRACE)
60 #ifndef HAVE_ANDROID_OS
61 #define HAVE_ANDROID_OS
62 #endif
63 #define ATRACE_TAG (ATRACE_TAG_VIDEO | ATRACE_TAG_HAL)
64 #include <cutils/trace.h>
65 #define UMD_ATRACE_BEGIN(name) \
66 { \
67 if(atrace_switch) ATRACE_BEGIN(name); \
68 }
69 #define UMD_ATRACE_END \
70 { \
71 if(atrace_switch) ATRACE_END(); \
72 }
73 #include <cutils/properties.h>
74 static int32_t atrace_switch = 0;
75 #else
76 #define UMD_ATRACE_BEGIN __noop
77 #define UMD_ATRACE_END __noop
78 #endif
79 #else
80 #define UMD_ATRACE_BEGIN __noop
81 #define UMD_ATRACE_END __noop
82 #endif
83
84 #define DDI_UNUSED(param) MOS_UNUSED(param)
85
86 // heap
87 #define DDI_MEDIA_HEAP_INCREMENTAL_SIZE 8
88
89
90 #define DDI_MEDIA_VACONTEXTID_OFFSET_MFE 0x70000000
91 #define DDI_MEDIA_VACONTEXTID_OFFSET_CM 0x80000000
92
93 #ifndef VA_FOURCC_ABGR
94 #define VA_FOURCC_ABGR VA_FOURCC('A', 'B', 'G', 'R')
95 #endif
96
97 #ifndef VA_FOURCC_R5G6B5
98 #define VA_FOURCC_R5G6B5 VA_FOURCC('R','G','1', '6')
99 #endif
100
101 #ifndef VA_FOURCC_R8G8B8
102 #define VA_FOURCC_R8G8B8 VA_FOURCC('R','G','2', '4')
103 #endif
104
105 #ifndef VA_FOURCC_I420
106 #define VA_FOURCC_I420 VA_FOURCC('I','4','2', '0')
107 #endif
108
109 #define RGB_10BIT_ALPHAMASK VA_RT_FORMAT_RGB32_10BPP
110 #define RGB_8BIT_ALPHAMASK 0
111
112 #define MEDIAAPI_EXPORT __attribute__((visibility("default")))
113
114 class MediaLibvaCaps;
115 class MediaLibvaCapsNext;
116
117 #include "ddi_media_context.h"
118 typedef struct DDI_MEDIA_CONTEXT *PDDI_MEDIA_CONTEXT;
119
120 static __inline PDDI_MEDIA_CONTEXT DdiMedia_GetMediaContext (VADriverContextP ctx)
121 {
122 return (PDDI_MEDIA_CONTEXT)ctx->pDriverData;
123 }
124
125 //!
126 //! \brief Media surface to mos resource
127 //!
128 //! \param [in] mediaSurface
129 //! Ddi media surface
130 //! \param [in] mhalOsResource
131 //! Mos resource
132 //!
133 void DdiMedia_MediaSurfaceToMosResource(DDI_MEDIA_SURFACE *mediaSurface, MOS_RESOURCE *mhalOsResource);
134
135 //!
136 //! \brief Media buffer to mos resource
137 //!
138 //! \param [in] mediaBuffer
139 //! Ddi media buffer
140 //! \param [in] mhalOsResource
141 //! Mos resource
142 //!
143 void DdiMedia_MediaBufferToMosResource(DDI_MEDIA_BUFFER *mediaBuffer, MOS_RESOURCE *mhalOsResource);
144
145 //!
146 //! \brief Get context from context ID
147 //!
148 //! \param [in] ctx
149 //! Pointer to VA driver context
150 //! \param [in] vaCtxID
151 //! VA context ID
152 //! \param [in] ctxType
153 //! Ctx type
154 //!
155 void* DdiMedia_GetContextFromContextID (VADriverContextP ctx, VAContextID vaCtxID, uint32_t *ctxType);
156
157 //!
158 //! \brief Get surface from VA surface ID
159 //!
160 //! \param [in] mediaCtx
161 //! Pointer to ddi media context
162 //! \param [in] surfaceID
163 //! VA surface ID
164 //!
165 //! \return DDI_MEDIA_SURFACE*
166 //! Pointer to ddi media surface
167 //!
168 DDI_MEDIA_SURFACE* DdiMedia_GetSurfaceFromVASurfaceID (PDDI_MEDIA_CONTEXT mediaCtx, VASurfaceID surfaceID);
169
170 //!
171 //! \brief replace the surface with given format
172 //!
173 //! \param [in] surface
174 //! Pointer to the old surface
175 //! \param [in] expectedFormat
176 //! VA surface ID
177 //!
178 //! \return DDI_MEDIA_SURFACE*
179 //! Pointer to new ddi media surface
180 //!
181 PDDI_MEDIA_SURFACE DdiMedia_ReplaceSurfaceWithNewFormat(PDDI_MEDIA_SURFACE surface, DDI_MEDIA_FORMAT expectedFormat);
182
183 //!
184 //! \brief replace the surface with correlation variant format
185 //!
186 //! \param [in] surface
187 //! Pointer to the old surface
188 //!
189 //! \return DDI_MEDIA_SURFACE*
190 //! Pointer to new ddi media surface
191 //!
192 PDDI_MEDIA_SURFACE DdiMedia_ReplaceSurfaceWithVariant(PDDI_MEDIA_SURFACE surface, VAEntrypoint entrypoint);
193
194 //!
195 //! \brief Get VA surface ID from surface
196 //!
197 //! \param [in] surface
198 //! surface
199 //!
200 //! \return VASurfaceID
201 //! VA Surface ID
202 //!
203 VASurfaceID DdiMedia_GetVASurfaceIDFromSurface(PDDI_MEDIA_SURFACE surface);
204
205 //!
206 //! \brief Get buffer from VA buffer ID
207 //!
208 //! \param [in] mediaCtx
209 //! Pointer to ddi media context
210 //! \param [in] bufferID
211 //! VA buffer ID
212 //!
213 //! \return DDI_MEDIA_BUFFER*
214 //! Pointer to ddi media buffer
215 //!
216 DDI_MEDIA_BUFFER* DdiMedia_GetBufferFromVABufferID (PDDI_MEDIA_CONTEXT mediaCtx, VABufferID bufferID);
217
218 //!
219 //! \brief Get context from VA buffer ID
220 //!
221 //! \param [in] mediaCtx
222 //! Pointer to ddi media context
223 //! \param [in] bufferID
224 //! VA buffer ID
225 //!
226 //! \return void*
227 //! Pointer to context
228 //!
229 void* DdiMedia_GetContextFromVABufferID (PDDI_MEDIA_CONTEXT mediaCtx, VABufferID bufferID);
230
231 //!
232 //! \brief Destroy buffer from VA buffer ID
233 //!
234 //! \param [in] mediaCtx
235 //! Pointer to ddi media context
236 //! \param [in] bufferID
237 //! VA buffer ID
238 //!
239 //! \return bool
240 //! true if destroy buffer from VA buffer ID, else false
241 //!
242 bool DdiMedia_DestroyBufFromVABufferID (PDDI_MEDIA_CONTEXT mediaCtx, VABufferID bufferID);
243
244 //!
245 //! \brief Get gpu priority
246 //!
247 //! \param [in] ctx
248 //! Pointer to VA driver context
249 //! \param [in] buffers
250 //! VA buffer ID
251 //! \param [in] numBuffers
252 //! Number of buffers
253 //! \param [out] updatePriority
254 //! Update priority
255 //! \param [out] priority
256 //! Priority value
257 //! \return int32_t
258 //!
259 int32_t DdiMedia_GetGpuPriority (VADriverContextP ctx, VABufferID *buffers, int32_t numBuffers, bool *updatePriority, int32_t *priority);
260
261 //!
262 //! \brief Move a bufferID to the end of buffers
263 //!
264 //! \param [in,out] buffers
265 //! VA buffer ID
266 //! \param [in] priorityIndexInBuf
267 //! Location of priority buffer
268 //! \param [in] numBuffers
269 //! Number of buffers
270 //! \return void
271 //!
272 void MovePriorityBufferIdToEnd (VABufferID *buffers, int32_t priorityIndexInBuf, int32_t numBuffers);
273
274 #endif