xref: /aosp_15_r20/external/intel-media-driver/media_softlet/linux/common/ddi/ddi_media_functions.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 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 //!
23 //! \file     ddi_media_functions.h
24 //! \brief    ddi media functions head file
25 //!
26 
27 #ifndef __DDI_MEDIA_FUNCTIONS_H__
28 #define __DDI_MEDIA_FUNCTIONS_H__
29 
30 #include <stdint.h>
31 #include <va/va_version.h>
32 #include <va/va.h>
33 #include <va/va_backend.h>
34 #include "media_factory.h"
35 #include "media_class_trace.h"
36 
37 #define DDI_VP_NUM_INPUT_COLOR_STD          6                 /* Number of supported input color formats */
38 #define DDI_VP_NUM_OUT_COLOR_STD            6                 /* Number of supported output color formats*/
39 #define DDI_CODEC_NUM_FWD_REF               0                 /* Number of forward references */
40 #define DDI_CODEC_NUM_BK_REF                0                 /* Number of backward references */
41 typedef struct DDI_MEDIA_CONTEXT *PDDI_MEDIA_CONTEXT;
42 typedef struct _DDI_MEDIA_SURFACE DDI_MEDIA_SURFACE;
43 
44 class DdiMediaFunctions
45 {
46 public:
47 
~DdiMediaFunctions()48     virtual ~DdiMediaFunctions(){};
49 
50     //!
51     //! \brief  Create context
52     //!
53     //! \param  [in] ctx
54     //!         Pointer to VA driver context
55     //! \param  [in] configId
56     //!         VA config id
57     //! \param  [in] pictureWidth
58     //!         Picture width
59     //! \param  [in] pictureHeight
60     //!         Picture height
61     //! \param  [out] flag
62     //!         Create flag
63     //! \param  [in] renderTargets
64     //!         VA render traget
65     //! \param  [in] renderTargetsNum
66     //!         Number of render targets
67     //! \param  [out] context
68     //!         VA created context
69     //!
70     //! \return VAStatus
71     //!     VA_STATUS_SUCCESS if success, else fail reason
72     //!
73     virtual VAStatus CreateContext (
74         VADriverContextP  ctx,
75         VAConfigID        configId,
76         int32_t           pictureWidth,
77         int32_t           pictureHeight,
78         int32_t           flag,
79         VASurfaceID       *renderTargets,
80         int32_t           renderTargetsNum,
81         VAContextID       *context
82     );
83 
84     //!
85     //! \brief  Destroy context
86     //!
87     //! \param  [in] ctx
88     //!         Pointer to VA driver context
89     //! \param  [in] context
90     //!         VA context to destroy
91     //!
92     //! \return VAStatus
93     //!     VA_STATUS_SUCCESS if success, else fail reason
94     //!
95     virtual VAStatus DestroyContext (
96         VADriverContextP  ctx,
97         VAContextID       context
98     );
99 
100     //!
101     //! \brief  Create buffer
102     //!
103     //! \param  [in] ctx
104     //!         Pointer to VA driver context
105     //! \param  [in] context
106     //!         VA context id
107     //! \param  [in] type
108     //!         VA buffer type
109     //! \param  [in] size
110     //!         Buffer size
111     //! \param  [out] elementsNum
112     //!         Number of elements
113     //! \param  [in] data
114     //!         Buffer data
115     //! \param  [out] bufId
116     //!         VA buffer id
117     //!
118     //! \return VAStatus
119     //!     VA_STATUS_SUCCESS if success, else fail reason
120     //!
121     virtual VAStatus CreateBuffer (
122         VADriverContextP  ctx,
123         VAContextID       context,
124         VABufferType      type,
125         uint32_t          size,
126         uint32_t          elementsNum,
127         void              *data,
128         VABufferID        *bufId
129     );
130 
131     //!
132     //! \brief  Map data store of the buffer into the client's address space
133     //!         vaCreateBuffer() needs to be called with "data" set to nullptr before
134     //!         calling vaMapBuffer()
135     //!
136     //! \param  [in] mediaCtx
137     //!         Pointer to media context
138     //! \param  [in] bufId
139     //!         VA buffer ID
140     //! \param  [out] buf
141     //!         Pointer to buffer
142     //! \param  [in] flag
143     //!         Flag
144     //!
145     //! \return VAStatus
146     //!     VA_STATUS_SUCCESS if success, else fail reason
147     //!
148     virtual VAStatus MapBufferInternal(
149         DDI_MEDIA_CONTEXT   *mediaCtx,
150         VABufferID          bufId,
151         void                **buf,
152         uint32_t            flag
153     );
154 
155     //! \brief  Unmap buffer
156     //!
157     //! \param  [in] mediaCtx
158     //!         Pointer to media context
159     //! \param  [in] bufId
160     //!         VA buffer ID
161     //!
162     //! \return VAStatus
163     //!     VA_STATUS_SUCCESS if success, else fail reason
164     //!
165     virtual VAStatus UnmapBuffer (
166         DDI_MEDIA_CONTEXT   *mediaCtx,
167         VABufferID          bufId
168     );
169 
170     //!
171     //! \brief  Destroy buffer
172     //!
173     //! \param  [in] mediaCtx
174     //!         Pointer to media context
175     //! \param  [in] bufId
176     //!         VA buffer ID
177     //!
178     //! \return     VAStatus
179     //!     VA_STATUS_SUCCESS if success, else fail reason
180     //!
181     virtual VAStatus DestroyBuffer(
182         DDI_MEDIA_CONTEXT  *mediaCtx,
183         VABufferID         bufId
184     );
185 
186     //!
187     //! \brief  Get ready to decode a picture to a target surface
188     //!
189     //! \param  [in] ctx
190     //!         Pointer to VA driver context
191     //! \param  [in] context
192     //!         VA context id
193     //! \param  [in] renderTarget
194     //!         VA render target surface
195     //!
196     //! \return VAStatus
197     //!     VA_STATUS_SUCCESS if success, else fail reason
198     //!
199     virtual VAStatus BeginPicture (
200         VADriverContextP  ctx,
201         VAContextID       context,
202         VASurfaceID       renderTarget
203     );
204 
205     //!
206     //! \brief  Send decode buffers to the server
207     //! \details    Buffers are automatically destroyed afterwards
208     //! \param  [in] ctx
209     //!         Pointer to VA driver context
210     //! \param  [in] context
211     //!         VA buffer id
212     //! \param  [in] buffer
213     //!         Pointer to VA buffer id
214     //! \param  [in] buffersNum
215     //!         number of buffers
216     //!
217     //! \return VAStatus
218     //!     VA_STATUS_SUCCESS if success, else fail reason
219     //!
220     virtual VAStatus RenderPicture (
221         VADriverContextP  ctx,
222         VAContextID       context,
223         VABufferID        *buffers,
224         int32_t           buffersNum
225     );
226 
227     //!
228     //! \brief  Make the end of rendering for a picture
229     //! \details    The server should start processing all pending operations for this
230     //!             surface. This call is non-blocking. The client can start another
231     //!             Begin/Render/End sequence on a different render target
232     //! \param  [in] ctx
233     //!         Pointer to VA driver context
234     //! \param  [in] context
235     //!         VA buffer id
236     //!
237     //! \return VAStatus
238     //!     VA_STATUS_SUCCESS if success, else fail reason
239     //!
240     virtual VAStatus EndPicture (
241         VADriverContextP  ctx,
242         VAContextID       context
243     );
244 
245     //!
246     //! \brief  Create a configuration for the encode/decode/vp pipeline
247     //! \details    it passes in the attribute list that specifies the attributes it cares
248     //!             about, with the rest taking default values.
249     //!
250     //! \param  [in] ctx
251     //!         Pointer to VA driver context
252     //! \param  [in] profile
253     //!         VA profile of configuration
254     //! \param  [in] entrypoint
255     //!         VA entrypoint of configuration
256     //! \param  [out] attribList
257     //!         VA attrib list
258     //! \param  [out] attribsNum
259     //!         Number of attribs
260     //! \param  [out] configId
261     //!         VA config id
262     //!
263     //! \return VAStatus
264     //!     VA_STATUS_SUCCESS if success, else fail reason
265     //!
266     virtual VAStatus CreateConfig (
267         VADriverContextP  ctx,
268         VAProfile         profile,
269         VAEntrypoint      entrypoint,
270         VAConfigAttrib    *attriblist,
271         int32_t           attribsNum,
272         VAConfigID        *configId
273     );
274 
275     //!
276     //! \brief  Query video proc filters
277     //!
278     //! \param  [in] ctx
279     //!         Pointer to VA driver context
280     //! \param  [in] context
281     //!         VA context ID
282     //! \param  [in] filters
283     //!         VA proc filter type
284     //! \param  [in] filtersNum
285     //!         Number of filters
286     //!
287     //! \return VAStatus
288     //!     VA_STATUS_SUCCESS if success, else fail reason
289     //!
290     virtual VAStatus QueryVideoProcFilters (
291         VADriverContextP  ctx,
292         VAContextID       context,
293         VAProcFilterType  *filters,
294         uint32_t          *filtersNum
295     );
296 
297     //!
298     //! \brief  Query video processing filter capabilities.
299     //!         The real implementation is in media_libva_vp.c, since it needs to use some definitions in vphal.h.
300     //!
301     //! \param  [in] ctx
302     //!         Pointer to VA driver context
303     //! \param  [in] context
304     //!         VA context ID
305     //! \param  [in] type
306     //!         VA proc filter type
307     //! \param  [inout] filterCaps
308     //!         FIlter caps
309     //! \param  [inout] filterCapsNum
310     //!         Number of filter caps
311     //!
312     //! \return VAStatus
313     //!     VA_STATUS_SUCCESS if success, else fail reason
314     //!
315     virtual VAStatus QueryVideoProcFilterCaps (
316         VADriverContextP  ctx,
317         VAContextID       context,
318         VAProcFilterType  type,
319         void              *filterCaps,
320         uint32_t          *filterCapsNum
321     );
322 
323     //!
324     //! \brief  Query video proc pipeline caps
325     //!
326     //! \param  [in] ctx
327     //!         Pointer to VA driver context
328     //! \param  [in] context
329     //!         VA context ID
330     //! \param  [in] filters
331     //!         VA buffer ID
332     //! \param  [in] filtersNum
333     //!         Number of filters
334     //! \param  [in] pipelineCaps
335     //!         VA proc pipeline caps
336     //!
337     //! \return VAStatus
338     //!     VA_STATUS_SUCCESS if success, else fail reason
339     //!
340     virtual VAStatus QueryVideoProcPipelineCaps (
341         VADriverContextP    ctx,
342         VAContextID         context,
343         VABufferID          *filters,
344         uint32_t            filtersNum,
345         VAProcPipelineCaps  *pipelineCaps
346     );
347 
348 #if VA_CHECK_VERSION(1,11,0)
349     //!
350     //! \brief   Create protected session
351     //!
352     //! \param   [in] ctx
353     //!          Pointer to VA driver context
354     //! \param   [in] configId
355     //!          VA configuration ID
356     //! \param   [out] protectedSession
357     //!          VA protected session ID
358     //!
359     //! \return  VAStatus
360     //!     VA_STATUS_SUCCESS if success, else fail reason
361     //!
362     virtual VAStatus CreateProtectedSession (
363         VADriverContextP      ctx,
364         VAConfigID            configId,
365         VAProtectedSessionID  *protectedSession
366     );
367 
368     //!
369     //! \brief   Destroy protected session
370     //!
371     //! \param   [in] ctx
372     //!          Pointer to VA driver context
373     //! \param   [in] protectedSession
374     //!          VA protected session ID
375     //!
376     //! \return  VAStatus
377     //!     VA_STATUS_SUCCESS if success, else fail reason
378     //!
379     virtual VAStatus DestroyProtectedSession (
380         VADriverContextP      ctx,
381         VAProtectedSessionID  protecteSsession
382     );
383 
384     //!
385     //! \brief   Attach protected session to display or context
386     //!
387     //! \param   [in] ctx
388     //!          Pointer to VA driver context
389     //! \param   [in] context
390     //!          VA context ID to be attached if not 0.
391     //! \param   [in] protectedSession
392     //!          VA protected session ID
393     //!
394     //! \return  VAStatus
395     //!     VA_STATUS_SUCCESS if success, else fail reason
396     //!
397     virtual VAStatus AttachProtectedSession (
398         VADriverContextP      ctx,
399         VAContextID           context,
400         VAProtectedSessionID  protectedSession
401     );
402 
403     //!
404     //! \brief   Detach protected session from display or context
405     //!
406     //! \param   [in] ctx
407     //!          Pointer to VA driver context
408     //! \param   [in] context
409     //!          VA context ID to be Detached if not 0.
410     //!
411     //! \return  VAStatus
412     //!     VA_STATUS_SUCCESS if success, else fail reason
413     //!
414     virtual VAStatus DetachProtectedSession (
415         VADriverContextP  ctx,
416         VAContextID       context
417     );
418 
419     //!
420     //! \brief   TEE execution for the particular protected session
421     //!
422     //! \param   [in] ctx
423     //!          Pointer to VA driver context
424     //! \param   [in] protectedSession
425     //!          VA protected session ID
426     //! \param   [in] data
427     //!          VA buffer ID
428     //!
429     //! \return  VAStatus
430     //!     VA_STATUS_SUCCESS if success, else fail reason
431     //!
432     virtual VAStatus ProtectedSessionExecute (
433         VADriverContextP      ctx,
434         VAProtectedSessionID  protectedSession,
435         VABufferID            data
436     );
437 
438 #endif
439 
440     //!
441     //! \brief   Status check after SyncSurface2
442     //!
443     //! \param   [in] mediaCtx
444     //!          Pointer to media driver context
445     //! \param   [in] surface
446     //!          DDI MEDIA SURFACE
447     //! \param   [in] VASurfaceID
448     //!          surface id
449     //!
450     //! \return  VAStatus
451     //!     VA_STATUS_SUCCESS if success, else fail reason
452     //!
453     virtual VAStatus StatusCheck(
454         PDDI_MEDIA_CONTEXT mediaCtx,
455         DDI_MEDIA_SURFACE  *surface,
456         VASurfaceID        surfaceId
457     );
458 
459     //!
460     //! \brief   Query Surface Error
461     //!
462     //! \param   [in] ctx
463     //!          Pointer to VA driver context
464     //! \param   [in] renderTarget
465     //!          VASurfaceID
466     //! \param   [in] errorStatus
467     //!          error Status
468     //! \param   [in] errorInfo
469     //!          error info
470     //!
471     //! \return  VAStatus
472     //!     VA_STATUS_SUCCESS if success, else fail reason
473     //!
474     virtual VAStatus QuerySurfaceError(
475         VADriverContextP ctx,
476         VASurfaceID      renderTarget,
477         VAStatus         errorStatus,
478         void             **errorInfo
479     );
480 
481     //! \brief  Ddi codec put surface linux hardware
482     //!
483     //! \param  ctx
484     //!     Pointer to VA driver context
485     //! \param  surface
486     //!     VA surface ID
487     //! \param  draw
488     //!     Drawable of window system
489     //! \param  srcx
490     //!     Source X of the region
491     //! \param  srcy
492     //!     Source Y of the region
493     //! \param  srcw
494     //!     Source W of the region
495     //! \param  srch
496     //!     Source H of the region
497     //! \param  destx
498     //!     Destination X
499     //! \param  desty
500     //!     Destination Y
501     //! \param  destw
502     //!     Destination W
503     //! \param  desth
504     //!     Destination H
505     //! \param  cliprects
506     //!     Client-supplied clip list
507     //! \param  numberCliprects
508     //!     Number of clip rects in the clip list
509     //! \param  flags
510     //!     De-interlacing flags
511     //!
512     //! \return     VAStatus
513     //!     VA_STATUS_SUCCESS if success, else fail reason
514     //!
515     virtual VAStatus PutSurface(
516         VADriverContextP ctx,
517         VASurfaceID      surface,
518         void             *draw,             /* Drawable of window system */
519         int16_t          srcx,
520         int16_t          srcy,
521         uint16_t         srcw,
522         uint16_t         srch,
523         int16_t          destx,
524         int16_t          desty,
525         uint16_t         destw,
526         uint16_t         desth,
527         VARectangle      *cliprects,        /* client supplied clip list */
528         uint32_t         numberCliprects,  /* number of clip rects in the clip list */
529         uint32_t         flags             /* de-interlacing flags */
530     );
531 
532     //! \brief  Ddi process pipeline
533     //!
534     //! \param  pVaDrvCtx
535     //!     Pointer to VA driver context
536     //! \param  ctxID
537     //!     VA context ID
538     //! \param  srcSurface
539     //!     VA src surface ID
540     //! \param  srcRect
541     //!     VA src rect
542     //! \param  dstSurface
543     //!     VA dst surface ID
544     //! \param  dstRect
545     //!     VA dst rect
546     //!
547     //! \return     VAStatus
548     //!     VA_STATUS_SUCCESS if success, else fail reason
549     //!
550     virtual VAStatus ProcessPipeline(
551         VADriverContextP    vaDrvCtx,
552         VAContextID         ctxID,
553         VASurfaceID         srcSurface,
554         VARectangle         *srcRect,
555         VASurfaceID         dstSurface,
556         VARectangle         *dstRect
557     );
558 
559 protected:
560     static const VAProcColorStandardType   m_vpInputColorStd[DDI_VP_NUM_INPUT_COLOR_STD];
561     static const VAProcColorStandardType   m_vpOutputColorStd[DDI_VP_NUM_OUT_COLOR_STD];
562 
563 MEDIA_CLASS_DEFINE_END(DdiMediaFunctions)
564 };
565 
566 enum CompType
567 {
568     CompCommon = 0,
569     CompCodec  = 1,
570     CompEncode = 2,
571     CompDecode = 3,
572     CompVp     = 4,
573     CompCp     = 5,
574     CompCount
575 };
576 
577 typedef MediaFactory<CompType, DdiMediaFunctions> FunctionsFactory;
578 
579 #endif //__DDI_MEDIA_FUNCTIONS_H__
580