Debian Codegraph @

media_softlet/linux/common/ddi/media_capstable_specific.cpp

raw
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 //!
24 //! \file media_capstable_specific.cpp
25 //! \brief implemantation of media caps table class on specific os
26 //!
27
28 #include "media_capstable_specific.h"
29 #include "media_libva.h"
30 #include "hwinfo_linux.h"
31 #include "linux_system_info.h"
32 #include "media_libva_caps_factory.h"
33 #include "ddi_cp_caps_interface.h"
34
35 bool operator<(const ComponentInfo &lhs, const ComponentInfo &rhs)
36 {
37 return memcmp(&lhs, &rhs, sizeof(ComponentInfo)) < 0;
38 }
39
40 MediaCapsTableSpecific::~MediaCapsTableSpecific()
41 {
42 if(m_cpCaps)
43 {
44 MOS_Delete(m_cpCaps);
45 m_cpCaps = nullptr;
46 }
47 }
48
49 MediaCapsTableSpecific::MediaCapsTableSpecific(HwDeviceInfo &deviceInfo)
50 {
51 m_plt.ipVersion = deviceInfo.ipVersion;
52 m_plt.usRevId = deviceInfo.usRevId;
53
54 MediaCapsTable::Iterator capsIter;
55 if(GetCapsTablePlatform(m_plt, capsIter))
56 {
57 m_profileMap = const_cast<ProfileMap *>(capsIter->second.profileMap);
58 m_imgTbl = const_cast<ImgTable *>(capsIter->second.imgTbl);
59 }
60 else
61 {
62 DDI_ASSERTMESSAGE("unknown platform with usRevId=%d, ipVersion=%d\n", (int)m_plt.usRevId, (int)m_plt.ipVersion);
63 }
64 }
65
66 VAStatus MediaCapsTableSpecific::Init(DDI_MEDIA_CONTEXT *mediaCtx)
67 {
68 DDI_FUNC_ENTER;
69
70 if (m_profileMap == nullptr)
71 {
72 DDI_ASSERTMESSAGE("Invalid parameter for profileMap");
73 return VA_STATUS_ERROR_INVALID_PARAMETER;
74 }
75
76 m_cpCaps = CreateDdiCpCaps();
77 DDI_CHK_NULL(m_cpCaps, "CP caps fail with null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
78
79 if (m_cpCaps->InitProfileMap(mediaCtx, m_profileMap) != VA_STATUS_SUCCESS)
80 {
81 DDI_ASSERTMESSAGE("Init CP caps failed");
82 MOS_Delete(m_cpCaps);
83 m_cpCaps = nullptr;
84 return VA_STATUS_ERROR_INVALID_PARAMETER;
85 }
86
87 for (auto profileMapIter: *m_profileMap)
88 {
89 auto profile = profileMapIter.first;
90 for(auto entrypointMapIter: *profileMapIter.second)
91 {
92 auto entrypoint = entrypointMapIter.first;
93 auto entrypointData = entrypointMapIter.second;
94 DDI_CHK_NULL(entrypointData, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
95
96 auto attriblist = entrypointData->attribList;
97 DDI_CHK_NULL(attriblist, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
98
99 auto componentData = entrypointData->configDataList;
100 int32_t numAttribList = attriblist->size();
101 if(componentData && componentData->size() != 0)
102 {
103 for(int i = 0; i < componentData->size(); i++)
104 {
105 auto configData = componentData->at(i);
106 m_configList.emplace_back(profile, entrypoint, const_cast<VAConfigAttrib*>(attriblist->data()), numAttribList, configData);
107 }
108 }
109 else
110 {
111 ComponentData configData = {};
112 m_configList.emplace_back(profile, entrypoint, const_cast<VAConfigAttrib*>(attriblist->data()), numAttribList, configData);
113 }
114 }
115 }
116
117 return VA_STATUS_SUCCESS;
118 }
119
120 VAStatus MediaCapsTableSpecific::QueryConfigProfiles(
121 VAProfile *profileList,
122 int32_t *profilesNum)
123 {
124 DDI_FUNC_ENTER;
125
126 DDI_CHK_NULL(profileList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
127 DDI_CHK_NULL(profilesNum, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
128
129 int i = 0;
130
131 if(m_profileMap->size() <= 0)
132 {
133 return VA_STATUS_ERROR_INVALID_CONFIG;
134 }
135
136 for (auto it = m_profileMap->begin(); it!=m_profileMap->end(); ++it)
137 {
138 profileList[i++] = (VAProfile)(it->first);
139 }
140 *profilesNum = m_profileMap->size();
141 return VA_STATUS_SUCCESS;
142 }
143
144 EntrypointMap* MediaCapsTableSpecific::QueryConfigEntrypointsMap(
145 VAProfile profile)
146 {
147 DDI_FUNC_ENTER;
148
149 int i = 0;
150
151 if(m_profileMap->find(profile) == m_profileMap->end())
152 {
153 return nullptr;
154 }
155
156 return const_cast<EntrypointMap*>(m_profileMap->at(profile));
157 }
158
159 AttribList* MediaCapsTableSpecific::QuerySupportedAttrib(
160 VAProfile profile,
161 VAEntrypoint entrypoint)
162 {
163 DDI_FUNC_ENTER;
164
165 if(m_profileMap->find(profile) == m_profileMap->end() ||
166 m_profileMap->at(profile)->find(entrypoint) == m_profileMap->at(profile)->end())
167 {
168 return nullptr;
169 }
170
171 return const_cast<AttribList*>(m_profileMap->at(profile)->at(entrypoint)->attribList);
172 }
173
174 ConfigList* MediaCapsTableSpecific::GetConfigList()
175 {
176 DDI_FUNC_ENTER;
177
178 return &m_configList;
179 }
180
181 ConfigLinux* MediaCapsTableSpecific::QueryConfigItemFromIndex(
182 VAConfigID configId)
183 {
184 DDI_FUNC_ENTER;
185
186 if (!IS_VALID_CONFIG_ID(configId))
187 {
188 DDI_ASSERTMESSAGE("Invalid config ID");
189 return nullptr;
190 }
191
192 if(IsDecConfigId(configId) && REMOVE_CONFIG_ID_DEC_OFFSET(configId) < m_configList.size())
193 {
194 return &m_configList[REMOVE_CONFIG_ID_DEC_OFFSET(configId)];
195 }
196 else if(IsEncConfigId(configId) && REMOVE_CONFIG_ID_ENC_OFFSET(configId) < m_configList.size())
197 {
198 return &m_configList[REMOVE_CONFIG_ID_ENC_OFFSET(configId)];
199 }
200 else if(IsVpConfigId(configId) && REMOVE_CONFIG_ID_VP_OFFSET(configId) < m_configList.size())
201 {
202 return &m_configList[REMOVE_CONFIG_ID_VP_OFFSET(configId)];
203 }
204 else if((m_cpCaps != nullptr) && (m_cpCaps->IsCpConfigId(configId)))
205 {
206 uint32_t index = m_cpCaps->GetCpConfigId(configId);
207 DDI_CHK_CONDITION((index >= m_configList.size()), "Invalid config ID", nullptr)
208
209 return &m_configList[index];
210 }
211 else
212 {
213 DDI_ASSERTMESSAGE("Invalid config ID");
214 return nullptr;
215 }
216 }
217
218 VAStatus MediaCapsTableSpecific::CreateConfig(
219 VAProfile profile,
220 VAEntrypoint entrypoint,
221 VAConfigAttrib *attribList,
222 int32_t numAttribs,
223 VAConfigID *configId)
224 {
225 DDI_FUNC_ENTER;
226
227 DDI_UNUSED(attribList);
228 DDI_UNUSED(numAttribs);
229 DDI_UNUSED(configId);
230
231 VAStatus ret = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
232 for (auto configItem : m_configList)
233 {
234 // check profile, entrypoint here
235 if (configItem.profile == profile)
236 {
237 ret = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
238 if(configItem.entrypoint == entrypoint)
239 {
240 ret = VA_STATUS_SUCCESS;
241 break;
242 }
243 }
244 }
245
246 return ret;
247 }
248
249 bool MediaCapsTableSpecific::IsProfileSupported(
250 VAProfile profile)
251 {
252 return !(m_profileMap->find(profile) == m_profileMap->end());
253 }
254
255 bool MediaCapsTableSpecific::IsEntrypointSupported(
256 VAProfile profile,
257 VAEntrypoint entrypoint)
258 {
259 return !(m_profileMap->at(profile)->find(entrypoint) == m_profileMap->at(profile)->end());
260 }
261
262 bool MediaCapsTableSpecific::IsDecConfigId(VAConfigID configId)
263 {
264 VAConfigID curConfigId = REMOVE_CONFIG_ID_OFFSET(configId);
265
266 return ((curConfigId >= DDI_CODEC_GEN_CONFIG_ATTRIBUTES_DEC_BASE) &&
267 (curConfigId <= DDI_CODEC_GEN_CONFIG_ATTRIBUTES_DEC_MAX));
268 }
269
270 bool MediaCapsTableSpecific::IsEncConfigId(VAConfigID configId)
271 {
272 VAConfigID curConfigId = REMOVE_CONFIG_ID_OFFSET(configId);
273
274 return ((curConfigId >= DDI_CODEC_GEN_CONFIG_ATTRIBUTES_ENC_BASE) &&
275 (curConfigId <= DDI_CODEC_GEN_CONFIG_ATTRIBUTES_ENC_MAX));
276 }
277
278 bool MediaCapsTableSpecific::IsVpConfigId(VAConfigID configId)
279 {
280 VAConfigID curConfigId = REMOVE_CONFIG_ID_OFFSET(configId);
281
282 return ((curConfigId >= DDI_VP_GEN_CONFIG_ATTRIBUTES_BASE) &&
283 (curConfigId <= DDI_VP_GEN_CONFIG_ATTRIBUTES_MAX));
284 }
285
286 VAStatus MediaCapsTableSpecific::DestroyConfig(VAConfigID configId)
287 {
288 uint32_t index = 0;
289 VAStatus status = VA_STATUS_SUCCESS;
290 DDI_FUNC_ENTER;
291
292 if(!IS_VALID_CONFIG_ID(configId))
293 {
294 DDI_ASSERTMESSAGE("Invalid config ID");
295 return VA_STATUS_ERROR_INVALID_CONFIG;
296 }
297
298 if(IsDecConfigId(configId))
299 {
300 index = REMOVE_CONFIG_ID_DEC_OFFSET(configId);
301 }
302 else if(IsEncConfigId(configId))
303 {
304 index = REMOVE_CONFIG_ID_ENC_OFFSET(configId);
305 }
306 else if(IsVpConfigId(configId))
307 {
308 index = REMOVE_CONFIG_ID_VP_OFFSET(configId);
309 }
310 else if( (m_cpCaps != nullptr) && (m_cpCaps->IsCpConfigId(configId)) )
311 {
312 index = m_cpCaps->GetCpConfigId(configId);
313 }
314 else
315 {
316 DDI_ASSERTMESSAGE("Invalid config ID");
317 return VA_STATUS_ERROR_INVALID_CONFIG;
318 }
319
320 if(index < m_configList.size())
321 {
322 DDI_NORMALMESSAGE("Succeed Destroy config ID");
323 status = VA_STATUS_SUCCESS;
324 }
325 else
326 {
327 DDI_NORMALMESSAGE("Invalid config ID");
328 status = VA_STATUS_ERROR_INVALID_CONFIG;
329 }
330
331 return status;
332 }
333
334 ImgTable* MediaCapsTableSpecific::GetImgTable()
335 {
336 DDI_FUNC_ENTER;
337
338 return m_imgTbl;
339 }
340
341 uint32_t MediaCapsTableSpecific::GetImageFormatsMaxNum()
342 {
343 DDI_FUNC_ENTER;
344
345 return m_imgTbl->size();
346 }
347
348 ProfileSurfaceAttribInfo* MediaCapsTableSpecific::QuerySurfaceAttributesFromConfigId(
349 VAConfigID configId)
350 {
351 DDI_FUNC_ENTER;
352
353 if (!IS_VALID_CONFIG_ID(configId))
354 {
355 DDI_ASSERTMESSAGE("Invalid config ID");
356 return nullptr;
357 }
358
359 ConfigLinux* configItem = nullptr;
360 configItem = QueryConfigItemFromIndex(configId);
361 DDI_CHK_NULL(configItem, "Invalid config id!", nullptr);
362
363 VAProfile profile = configItem->profile;
364 VAEntrypoint entrypoint = configItem->entrypoint;
365
366 uint32_t i = 0;
367
368 if (m_profileMap->find(profile) == m_profileMap->end() ||
369 m_profileMap->at(profile)->find(entrypoint) == m_profileMap->at(profile)->end())
370 {
371 return nullptr;
372 }
373
374 return const_cast<ProfileSurfaceAttribInfo*>(m_profileMap->at(profile)->at(entrypoint)->surfaceAttrib);
375 }