1 /*
2 * Copyright (c) 2009-2020, 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_decoder.h
24 //! \brief libva(and its extension) decoder head file
25 //!
26
27 #ifndef __MEDIA_LIBVA_DECODER_H__
28 #define __MEDIA_LIBVA_DECODER_H__
29
30 #include "media_libva.h"
31 #include "media_libva_cp_interface.h"
32 #include "media_ddi_decode_base.h"
33
34 #define DDI_DECODE_SFC_MAX_WIDTH 4096
35 #define DDI_DECODE_SFC_MAX_HEIGHT 4096
36 #define DDI_DECODE_SFC_MIN_WIDTH 128
37 #define DDI_DECODE_SFC_MIN_HEIGHT 128
38 #define DDI_DECODE_HCP_SFC_MAX_WIDTH (16*1024)
39 #define DDI_DECODE_HCP_SFC_MAX_HEIGHT (16*1024)
40
41 #if MOS_EVENT_TRACE_DUMP_SUPPORTED
42
43 #define MACROBLOCK_HEIGHT 16
44 #define MACROBLOCK_WIDTH 16
45
46 typedef struct _DECODE_EVENTDATA_INFO_PICTURE
47 {
48 uint32_t CodecFormat;
49 uint32_t FrameType;
50 uint32_t PicStruct;
51 uint32_t Width;
52 uint32_t Height;
53 uint32_t Bitdepth;
54 uint32_t ChromaFormat;
55 bool EnabledSCC;
56 bool EnabledSegment;
57 bool EnabledFilmGrain;
58 } DECODE_EVENTDATA_INFO_PICTURE;
59
60 typedef struct _DECODE_EVENTDATA_INFO_PICTUREVA
61 {
62 uint32_t CodecFormat;
63 uint32_t FrameType;
64 uint32_t PicStruct;
65 uint32_t Width;
66 uint32_t Height;
67 uint32_t Bitdepth;
68 uint32_t ChromaFormat;
69 bool EnabledSCC;
70 bool EnabledSegment;
71 bool EnabledFilmGrain;
72 } DECODE_EVENTDATA_INFO_PICTUREVA;
73
74 typedef struct _DECODE_EVENTDATA_VA_DISPLAYINFO
75 {
76 uint32_t uiDisplayWidth;
77 uint32_t uiDisplayHeight;
78 } DECODE_EVENTDATA_VA_DISPLAYINFO;
79
80 typedef struct _DECODE_EVENTDATA_VA_CREATEBUFFER
81 {
82 VABufferType type;
83 uint32_t size;
84 uint32_t numElements;
85 VABufferID *bufId;
86 } DECODE_EVENTDATA_VA_CREATEBUFFER;
87
88 typedef struct _DECODE_EVENTDATA_VA_BEGINPICTURE_START
89 {
90 uint32_t FrameIndex;
91 } DECODE_EVENTDATA_VA_BEGINPICTURE_START;
92
93 typedef struct _DECODE_EVENTDATA_VA_BEGINPICTURE
94 {
95 uint32_t FrameIndex;
96 uint32_t hRes;
97 } DECODE_EVENTDATA_VA_BEGINPICTURE;
98
99 typedef struct _DECODE_EVENTDATA_VA_ENDPICTURE_START
100 {
101 uint32_t FrameIndex;
102 } DECODE_EVENTDATA_VA_ENDPICTURE_START;
103
104 typedef struct _DECODE_VA_EVENTDATA_ENDPICTURE
105 {
106 uint32_t FrameIndex;
107 uint32_t hRes;
108 } DECODE_EVENTDATA_VA_ENDPICTURE;
109
110
111 typedef struct _DECODE_EVENTDATA_VA_RENDERPICTURE_START
112 {
113 VABufferID *buffers;
114 } DECODE_EVENTDATA_VA_RENDERPICTURE_START;
115
116 typedef struct _DECODE_EVENTDATA_VA_RENDERPICTURE
117 {
118 VABufferID *buffers;
119 uint32_t hRes;
120 uint32_t numBuffers;
121 } DECODE_EVENTDATA_VA_RENDERPICTURE;
122
123 typedef struct _DECODE_EVENTDATA_VA_CREATECONTEXT_START
124 {
125 VABufferID configId;
126 } DECODE_EVENTDATA_VA_CREATECONTEXT_START;
127
128 typedef struct _DECODE_EVENTDATA_VA_CREATECONTEXT
129 {
130 VABufferID configId;
131 uint32_t hRes;
132 } DECODE_EVENTDATA_VA_CREATECONTEXT;
133
134 typedef struct _DECODE_EVENTDATA_VA_DESTROYCONTEXT_START
135 {
136 VABufferID context;
137 } DECODE_EVENTDATA_VA_DESTROYCONTEXT_START;
138
139 typedef struct _DECODE_EVENTDATA_VA_DESTROYCONTEXT
140 {
141 VABufferID context;
142 } DECODE_EVENTDATA_VA_DESTROYCONTEXT;
143
144 typedef struct _DECODE_EVENTDATA_VA_GETDECCTX
145 {
146 uint32_t bufferID;
147 } DECODE_EVENTDATA_VA_GETDECCTX;
148
149 typedef struct _DECODE_EVENTDATA_VA_FREEBUFFERHEAPELEMENTS
150 {
151 uint32_t bufNums;
152 } DECODE_EVENTDATA_VA_FREEBUFFERHEAPELEMENTS;
153
154 typedef struct _DECODE_EVENTDATA_VA_FEATURE_REPORTMODE
155 {
156 uint32_t wMode;
157 uint32_t ValueID;
158 } DECODE_EVENTDATA_VA_FEATURE_REPORTMODE;
159 #endif
160
161 //!
162 //! \struct DDI_DECODE_CONFIG_ATTR
163 //! \brief Ddi decode configuration attribute
164 //!
165 struct DDI_DECODE_CONFIG_ATTR
166 {
167 VAProfile profile;
168 VAEntrypoint entrypoint;
169 uint32_t uiDecSliceMode;
170 uint32_t uiEncryptionType;
171 uint32_t uiDecProcessingType;
172 };
173
174 typedef struct DDI_DECODE_CONFIG_ATTR *PDDI_DECODE_CONFIG_ATTR;
175
176 class DdiMediaDecode;
177 class DdiDecodeBase;
178 class DdiVpFunctions;
179
180 //!
181 //! \struct DDI_DECODE_CONTEXT
182 //! \brief Ddi decode context
183 //!
184 struct DDI_DECODE_CONTEXT
185 {
186 // Decoder data related with the specific codec
187 // The instance of DdiDecodeXXX. For example: DdiDecodeAvc, DdiDecodeJPEG
188 DdiMediaDecode *m_ddiDecode;
189 DdiDecodeBase *m_ddiDecodeNext;
190 // Decoder private data
191 DdiCpInterface *pCpDdiInterface;
192 DdiVpFunctions *pVpDdiInterface;
193 // Parameters
194 CodechalDecodeParams DecodeParams;
195 uint16_t wMode; // Get the info during hand shaking
196 Codechal *pCodecHal;
197 bool bShortFormatInUse;
198 bool bDecodeModeReported;
199 VASurfaceDecodeMBErrors vaSurfDecErrOutput[2];
200 DDI_CODEC_RENDER_TARGET_TABLE RTtbl;
201 DDI_CODEC_COM_BUFFER_MGR BufMgr;
202 PDDI_MEDIA_CONTEXT pMediaCtx;
203 // Add a list to track DPB.
204 VASurfaceID RecListSurfaceID[CODEC_AVC_NUM_UNCOMPRESSED_SURFACE];
205 uint32_t dwSliceParamBufNum;
206 uint32_t dwSliceCtrlBufNum;
207 uint32_t uiDecProcessingType;
208 };
209
210 typedef struct DDI_DECODE_CONTEXT *PDDI_DECODE_CONTEXT;
211
DdiDecode_GetDecContextFromPVOID(void * decCtx)212 static __inline PDDI_DECODE_CONTEXT DdiDecode_GetDecContextFromPVOID (void *decCtx)
213 {
214 return (PDDI_DECODE_CONTEXT)decCtx;
215 }
216
217 //!
218 //! \brief Status report
219 //!
220 //! \param [in] decoder
221 //! CodechalDecode decoder
222 //!
223 //! \return VAStatus
224 //! VA_STATUS_SUCCESS if success, else fail reason
225 //!
226 VAStatus DdiDecode_StatusReport(
227 PDDI_MEDIA_CONTEXT mediaCtx,
228 CodechalDecode *decoder,
229 DDI_MEDIA_SURFACE *surface);
230
231 //!
232 //! \brief Status report
233 //!
234 //! \param [in] decoder
235 //! DecodePipelineAdapter decoder
236 //!
237 //! \return VAStatus
238 //! VA_STATUS_SUCCESS if success, else fail reason
239 //!
240 VAStatus DdiDecode_StatusReport(
241 PDDI_MEDIA_CONTEXT mediaCtx,
242 DecodePipelineAdapter *decoder,
243 DDI_MEDIA_SURFACE *surface);
244
245 //!
246 //! \brief Create buffer
247 //!
248 //! \param [in] ctx
249 //! Pointer to VA driver context
250 //! \param [in] decCtx
251 //! Pointer to ddi decode context
252 //! \param [in] type
253 //! VA buffer type
254 //! \param [in] size
255 //! Size
256 //! \param [in] numElements
257 //! Number of elements
258 //! \param [in] data
259 //! DAta
260 //! \param [in] bufId
261 //! VA buffer ID
262 //!
263 //! \return VAStatus
264 //! VA_STATUS_SUCCESS if success, else fail reason
265 //!
266 VAStatus DdiDecode_CreateBuffer(
267 VADriverContextP ctx,
268 PDDI_DECODE_CONTEXT decCtx,
269 VABufferType type,
270 uint32_t size,
271 uint32_t numElements,
272 void *data,
273 VABufferID *bufId
274 );
275
276 //!
277 //! \brief Begin picture
278 //!
279 //! \param [in] ctx
280 //! Pointer to VA driver context
281 //! \param [in] context
282 //! VA context ID
283 //! \param [in] renderTarget
284 //! VA surface ID
285 //!
286 //! \return VAStatus
287 //! VA_STATUS_SUCCESS if success, else fail reason
288 //!
289 VAStatus DdiDecode_BeginPicture (
290 VADriverContextP ctx,
291 VAContextID context,
292 VASurfaceID renderTarget
293 );
294
295 //!
296 //! \brief End picture
297 //!
298 //! \param [in] ctx
299 //! Pointer to VA driver context
300 //! \param [in] context
301 //! VA context ID
302 //!
303 //! \return VAStatus
304 //! VA_STATUS_SUCCESS if success, else fail reason
305 //!
306 VAStatus DdiDecode_EndPicture (
307 VADriverContextP ctx,
308 VAContextID context
309 );
310
311 //!
312 //! \brief Render picture
313 //!
314 //! \param [in] ctx
315 //! Pointer to VA driver context
316 //! \param [in] context
317 //! VA context ID
318 //! \param [in] buffers
319 //! VA buffer ID
320 //! \param [in] numBuffers
321 //! Number of buffers
322 //!
323 //! \return VAStatus
324 //! VA_STATUS_SUCCESS if success, else fail reason
325 //!
326 VAStatus DdiDecode_RenderPicture (
327 VADriverContextP ctx,
328 VAContextID context,
329 VABufferID *buffers,
330 int32_t numBuffers
331 );
332
333 //!
334 //! \brief Create context
335 //!
336 //! \param [in] ctx
337 //! Pointer to VA driver context
338 //! \param [in] configId
339 //! VA configuration ID
340 //! \param [in] pictureWidth
341 //! The width of picture
342 //! \param [in] pictureHeight
343 //! The height of picture
344 //! \param [in] flag
345 //! Flag
346 //! \param [in] renderTargets
347 //! VA surface ID
348 //! \param [in] numRenderTargets
349 //! Number of render targets
350 //! \param [in] context
351 //! VA context ID
352 //!
353 //! \return VAStatus
354 //! VA_STATUS_SUCCESS if success, else fail reason
355 //!
356 VAStatus DdiDecode_CreateContext (
357 VADriverContextP ctx,
358 VAConfigID configId,
359 int32_t pictureWidth,
360 int32_t pictureHeight,
361 int32_t flag,
362 VASurfaceID *renderTargets,
363 int32_t numRenderTargets,
364 VAContextID *context
365 );
366
367 //!
368 //! \brief Destroy context
369 //!
370 //! \param [in] ctx
371 //! Pointer to VA driver context
372 //! \param [in] context
373 //! VA context ID
374 //!
375 //! \return VAStatus
376 //! VA_STATUS_SUCCESS if success, else fail reason
377 //!
378 VAStatus DdiDecode_DestroyContext (
379 VADriverContextP ctx,
380 VAContextID context
381 );
382
383 //!
384 //! \brief Set Decode Gpu priority
385 //!
386 //! \param [in] ctx
387 //! Pointer to VA driver context
388 //! \param [in] decode context
389 //! Pointer to decode context
390 //! \param [in] priority
391 //! priority
392 //! \return VAStatus
393 //!
394 VAStatus DdiDecode_SetGpuPriority(
395 VADriverContextP ctx,
396 PDDI_DECODE_CONTEXT decCtx,
397 int32_t priority
398 );
399
400 #endif
401