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