xref: /aosp_15_r20/external/intel-media-driver/media_driver/linux/common/ddi/media_ddi_base.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2017, 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_ddi_base.h
24 //! \brief    Defines base class for DDI media encode/decoder/VP
25 //!
26 
27 #ifndef _MEDIA_DDI_BASE_H_
28 #define _MEDIA_DDI_BASE_H_
29 
30 #include <stdint.h>
31 #include <va/va.h>
32 #include <va/va_backend.h>
33 
34 #include "media_libva.h"
35 #include "media_libva_util.h"
36 
37 #define SURFACE_STATE_INACTIVE              0   //!< Surface state inactive flag, should be transfer from inactive->inuse->active->inactive
38 #define SURFACE_STATE_ACTIVE_IN_LASTFRAME   1   //!< Surface state active in last frame flag, means surface appears in DPB of last frame and certainly some of them will appear in DPB of current frame.
39 #define SURFACE_STATE_ACTIVE_IN_CURFRAME    64  //!< Surface state active in current frame flag, means surface will be used in current frame.
40 
41 //!
42 //! \class  DdiMediaBase
43 //! \brief  Ddi media base class
44 //!
45 class DdiMediaBase
46 {
47 public:
48     //!
49     //! \brief Constructor
50     //!
DdiMediaBase()51     DdiMediaBase(){};
52 
53     //!
54     //! \brief Destructor
55     //!
~DdiMediaBase()56     virtual ~DdiMediaBase(){};
57 
58     //!
59     //! \brief    Get ready to process for a target surface
60     //! \details  It begins the process (encode/decode/vp) for a specified target surface
61     //!
62     //! \param    [in] ctx
63     //!           Pointer to VA driver context
64     //! \param    [in] context
65     //!           Already created context for the process
66     //! \param    [in] renderTarget
67     //!           Specified target surface
68     //!
69     //! \return   VAStatus
70     //!           VA_STATUS_SUCCESS if success, else fail reason
71     //!
72     virtual VAStatus BeginPicture(
73         VADriverContextP ctx,
74         VAContextID      context,
75         VASurfaceID      renderTarget) = 0;
76 
77     //!
78     //! \brief    Send required buffers to for process
79     //! \details  It sends needed buffers by the process (encode/decode/vp) to the driver
80     //!
81     //! \param    [in] ctx
82     //!           Pointer to VA driver context
83     //! \param    [in] context
84     //!           Already created context for the process
85     //! \param    [in] buffers
86     //!           Pointer to the buffer array
87     //! \param    [in] numBuffers
88     //!           Number of buffers in above array
89     //!
90     //! \return   VAStatus
91     //!           VA_STATUS_SUCCESS if success, else fail reason
92     //!
93     virtual VAStatus RenderPicture(
94         VADriverContextP ctx,
95         VAContextID      context,
96         VABufferID       *buffers,
97         int32_t          numBuffers) = 0;
98 
99     //!
100     //! \brief    Make the end of rendering for a picture
101     //! \details  The driver will start processing the corresponding decoding/encoding/vp for
102     //!           given context. This call is non-blocking. The app can start another
103     //!           Begin/Render/End sequence on a different render target
104     //!
105     //! \param    [in] ctx
106     //!           Pointer to VA driver context
107     //! \param    [in] context
108     //!           Already created context for the process
109     //!
110     //! \return   VAStatus
111     //!           VA_STATUS_SUCCESS if success, else fail reason
112     //!
113     virtual VAStatus EndPicture(
114         VADriverContextP ctx,
115         VAContextID      context) = 0;
116 
117     //!
118     //! \brief    Register Render Target Surface
119     //! \details  Register surface in render target table
120     //!
121     //! \param    [in] rtTbl
122     //!           Pointer to DDI_CODEC_RENDER_TARGET_TABLE
123     //! \param    [in] surface
124     //!           Pointer to DDI_MEDIA_SURFACE
125     //!
126     //! \return   VAStatus
127     //!           VA_STATUS_SUCCESS if success, else fail reason
128     //!
129     VAStatus RegisterRTSurfaces(DDI_CODEC_RENDER_TARGET_TABLE *rtTbl, DDI_MEDIA_SURFACE *surface);
130 
131     //!
132     //! \brief    Unregister Render Target Surface
133     //! \details  Unregister surface in render target table
134     //!
135     //! \param    [in] rtTbl
136     //!           Pointer to DDI_CODEC_RENDER_TARGET_TABLE
137     //! \param    [in] surface
138     //!           Pointer to DDI_MEDIA_SURFACE
139     //!
140     //! \return   VAStatus
141     //!           VA_STATUS_SUCCESS if success, else fail reason
142     //!
143     VAStatus UnRegisterRTSurfaces(DDI_CODEC_RENDER_TARGET_TABLE *rtTbl, DDI_MEDIA_SURFACE *surface);
144 
145 protected:
146     //!
147     //! \brief    Get Render Target Index
148     //! \details  Get surface index in render target table
149     //!
150     //! \param    [in] rtTbl
151     //!           Pointer to DDI_CODEC_RENDER_TARGET_TABLE
152     //! \param    [in] surface
153     //!           Pointer to DDI_MEDIA_SURFACE
154     //!
155     //! \return   int32_t
156     //!           Render target index
157     //!
158     int32_t GetRenderTargetID(DDI_CODEC_RENDER_TARGET_TABLE *rtTbl, DDI_MEDIA_SURFACE *surface);
159 
160     //!
161     //! \brief    Clear Reference List
162     //! \details  Clear surface state in render target table
163     //!
164     //! \param    [in] rtTbl
165     //!           Pointer to DDI_CODEC_RENDER_TARGET_TABLE
166     //! \param    [in] withDpb
167     //!           Dpb flag
168     //!
169     //! \return   VAStatus
170     //!           VA_STATUS_SUCCESS if success, else fail reason
171     //!
172     VAStatus ClearRefList(DDI_CODEC_RENDER_TARGET_TABLE *rtTbl, bool withDpb);
173 
174     //!
175     //! \brief    Update Registered Render Target Surface Flag
176     //! \details  Check if surface need to be registered in render target table
177     //!
178     //! \param    [in] rtTbl
179     //!           Pointer to DDI_CODEC_RENDER_TARGET_TABLE
180     //! \param    [in] surface
181     //!           Pointer to DDI_MEDIA_SURFACE
182     //!
183     //! \return   VAStatus
184     //!           VA_STATUS_SUCCESS if success, else fail reason
185     //!
186     VAStatus UpdateRegisteredRTSurfaceFlag(DDI_CODEC_RENDER_TARGET_TABLE *rtTbl, DDI_MEDIA_SURFACE *surface);
187 };
188 
189 #endif /*  _MEDIA_DDI_BASE_H_ */
190