xref: /aosp_15_r20/external/intel-media-driver/media_softlet/linux/common/ddi/media_capstable_specific.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2021-2022, 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_capstable_specific.h
24 //! \brief    Header file of media caps table class on specific os
25 //!
26 
27 #ifndef __MEDIA_CAPSTABLE_LINUX_H__
28 #define __MEDIA_CAPSTABLE_LINUX_H__
29 
30 #include <vector>
31 #include <map>
32 #include <set>
33 
34 #include "va/va.h"
35 #include "va/va_drmcommon.h"
36 #include "capstable_data_linux_definition.h"
37 #include "media_capstable.h"
38 
39 //!
40 //! \class  ConfigInfo
41 //! \brief  Component info to create specific component
42 //!
43 struct ComponentInfo
44 {
45     VAProfile       profile       = VAProfileNone;
46     VAEntrypoint    entrypoint    = VAEntrypointVLD;
ComponentInfoComponentInfo47     ComponentInfo(
48         VAProfile p,
49         VAEntrypoint e
50         ) : profile(p), entrypoint(e) {};
ComponentInfoComponentInfo51     ComponentInfo(){};
52 };
53 
54 bool operator<(const ComponentInfo &lhs, const ComponentInfo &rhs);
55 
56 //!
57 //! \class  ConfigLinux
58 //! \brief  Config for Linux caps
59 //!
60 struct ConfigLinux
61 {
62     VAProfile       profile       = VAProfileNone;
63     VAEntrypoint    entrypoint    = VAEntrypointVLD;
64     VAConfigAttrib  *attribList   = nullptr;
65     int32_t         numAttribs    = 0;
66     ComponentData   componentData = {};
67 
ConfigLinuxConfigLinux68     ConfigLinux(
69         VAProfile      p,
70         VAEntrypoint   e,
71         VAConfigAttrib *a,
72         int32_t        n,
73         ComponentData  c) : profile(p), entrypoint(e), attribList(a), numAttribs(n), componentData(c){}
ConfigLinuxConfigLinux74     ConfigLinux(){}
75 };
76 
77 typedef std::vector<ConfigLinux> ConfigList;
78 
79 #define CONFIG_ATTRIB_NONE 0x00000000
80 
81 // This offset is for cap fallback enabling, can be removed when all refactor done
82 #define CONFIG_ID_OFFSET 10000
83 #define ADD_CONFIG_ID_OFFSET(x) ((x) + CONFIG_ID_OFFSET)
84 #define ADD_CONFIG_ID_DEC_OFFSET(x) (ADD_CONFIG_ID_OFFSET(x) + DDI_CODEC_GEN_CONFIG_ATTRIBUTES_DEC_BASE)
85 #define ADD_CONFIG_ID_ENC_OFFSET(x) (ADD_CONFIG_ID_OFFSET(x) + DDI_CODEC_GEN_CONFIG_ATTRIBUTES_ENC_BASE)
86 #define ADD_CONFIG_ID_VP_OFFSET(x) (ADD_CONFIG_ID_OFFSET(x) + DDI_VP_GEN_CONFIG_ATTRIBUTES_BASE)
87 #define REMOVE_CONFIG_ID_OFFSET(x) ((x) - CONFIG_ID_OFFSET)
88 #define REMOVE_CONFIG_ID_DEC_OFFSET(x) (REMOVE_CONFIG_ID_OFFSET(x) - DDI_CODEC_GEN_CONFIG_ATTRIBUTES_DEC_BASE)
89 #define REMOVE_CONFIG_ID_ENC_OFFSET(x) (REMOVE_CONFIG_ID_OFFSET(x) - DDI_CODEC_GEN_CONFIG_ATTRIBUTES_ENC_BASE)
90 #define REMOVE_CONFIG_ID_VP_OFFSET(x) (REMOVE_CONFIG_ID_OFFSET(x) - DDI_VP_GEN_CONFIG_ATTRIBUTES_BASE)
91 #define IS_VALID_CONFIG_ID(x) ((x) >= CONFIG_ID_OFFSET)
92 
93 class DdiCpCapsInterface;
94 //!
95 //! \class  MediaLibvaCaps
96 //! \brief  Media libva caps
97 //!
98 class MediaCapsTableSpecific : public MediaCapsTable<CapsData>
99 {
100 private:
101     PlatformInfo  m_plt;
102     ProfileMap    *m_profileMap = nullptr;
103     ImgTable      *m_imgTbl     = nullptr;
104     DdiCpCapsInterface *m_cpCaps = nullptr;
105 
106 public:
107     //!
108     //! \brief  Store config
109     //!
110     ConfigList m_configList = {};
111 
112     //!
113     //! \brief    Constructor
114     //!
115     MediaCapsTableSpecific(HwDeviceInfo &deviceInfo);
116 
117     //!
118     //! \brief    Destructor
119     //!
120     ~MediaCapsTableSpecific();
121 
122     //!
123     //! \brief    Init configlist
124     //!
125     //! \param    [in] mediaCtx
126     //!           media context
127     //!
128     VAStatus Init(DDI_MEDIA_CONTEXT *mediaCtx);
129 
130     //!
131     //! \brief    Get configlist, this is for component createConfig
132     //!
133     ConfigList* GetConfigList();
134 
135     //!
136     //! \brief    Get Image Table
137     //!
138     //! \return   ImgTable
139     //!
140     ImgTable* GetImgTable();
141 
142     //!
143     //! \brief    Get Supported Attrib Value
144     //!
145     //! \param    [in] profile
146     //!           VA profile
147     //!
148     //! \param    [in] entrypoint
149     //!           VA entrypoint
150     //!
151     //! \return   AttribList*
152     //!           nullptr if query failed
153     //!
154     AttribList* QuerySupportedAttrib(
155         VAProfile      profile,
156         VAEntrypoint   entrypoint);
157 
158     //!
159     //! \brief    Get specific config item
160     //!
161     //! \param    [in] configId
162     //!           config list index
163     //!
164     //! \return   ConfigLinux
165     //!           nullptr if invalid index
166     //!
167     ConfigLinux* QueryConfigItemFromIndex(
168         VAConfigID    configId);
169 
170     //!
171     //! \brief    Create a configuration
172     //! \details  It passes in the attribute list that specifies the attributes it
173     //!           cares about, with the rest taking default values.
174     //!
175     //! \param    [in] profile
176     //!           VA profile
177     //!
178     //! \param    [in] entrypoint
179     //!           VA entrypoint
180     //!
181     //! \param    [in] attribList
182     //!           Pointer to VAConfigAttrib array that specifies the attributes
183     //!
184     //! \param    [in] numAttribs
185     //!           Number of VAConfigAttrib in the array attribList
186     //!
187     //! \param    [out] configId
188     //!           Pointer to returned VAConfigID if success
189     //!
190     //! \return   VAStatus
191     //!           VA_STATUS_SUCCESS if success
192     //!
193     VAStatus CreateConfig(
194         VAProfile       profile,
195         VAEntrypoint    entrypoint,
196         VAConfigAttrib  *attribList,
197         int32_t         numAttribs,
198         VAConfigID      *configId);
199 
200     //!
201     //! \brief    Check if the configID is a valid decode config
202     //!
203     //! \param    [in] configId
204     //!           Specify the VAConfigID
205     //!
206     //! \return   True if the configID is a valid decode config, otherwise false
207     //!
208     bool IsDecConfigId(VAConfigID configId);
209 
210     //!
211     //! \brief    Check if the configID is a valid encode config
212     //!
213     //! \param    [in] configId
214     //!           Specify the VAConfigID
215     //!
216     //! \return   True if the configID is a valid encode config, otherwise false
217     //!
218     bool IsEncConfigId(VAConfigID configId);
219 
220     //!
221     //! \brief    Check if the configID is a valid vp config
222     //!
223     //! \param    [in] configId
224     //!           Specify the VAConfigID
225     //!
226     //! \return   True if the configID is a valid vp config, otherwise false
227     //!
228     bool IsVpConfigId(VAConfigID configId);
229 
230     //!
231     //! \brief    Destory the VAConfigID
232     //!
233     //! \param    [in] configId
234     //!           Specify the VAConfigID
235     //!
236     //! \return   VAStatus
237     //!           VA_STATUS_SUCCESS if succeed
238     //!           VA_STATUS_ERROR_INVALID_CONFIG if the conifgId is invalid
239     //!
240     VAStatus DestroyConfig(VAConfigID configId);
241 
242     //!
243     //! \brief    Query EntrypointsMap
244     //!
245     //! \param    [in] configId
246     //!
247     //! \return   EntrypointMap*
248     //!           nullptr if invalid profile
249     //!
250     EntrypointMap* QueryConfigEntrypointsMap(
251         VAProfile      profile);
252 
253     //!
254     //! \brief    Query supported profiles
255     //!
256     //! \param    [in] profileList
257     //!           Pointer to VAProfile array that can hold at least vaMaxNumProfile() entries
258     //!
259     //! \param    [out] numProfiles
260     //!           Pointer to int32_t. It returns the actual number of supported profiles.
261     //!
262     //! \return   VAStatus
263     //!           VA_STATUS_SUCCESS if success
264     //!
265     VAStatus QueryConfigProfiles(
266         VAProfile *profileList,
267         int32_t   *profilesNum);
268 
269     //!
270     //! \brief    Query SurfaceAttributes From ConfigId
271     //!
272     //! \param    [in] configId
273     //!           Supported surface attrib
274     //!
275     //! \return   ProfileSurfaceAttribInfo*
276     //!           nullptr if invalid configid
277     //!
278     ProfileSurfaceAttribInfo* QuerySurfaceAttributesFromConfigId(
279         VAConfigID                configId);
280 
281     //!
282     //! \brief    Return the maxinum number of supported image formats for current platform ipVersion
283     //!
284     //! \return   The maxinum number of supported image formats for current platform ipVersion
285     //!
286     uint32_t GetImageFormatsMaxNum();
287 MEDIA_CLASS_DEFINE_END(MediaCapsTableSpecific)
288 };
289 
290 
291 #endif //__MEDIA_CAPSTABLE_LINUX_H__
292