1 /*
2 * Copyright (c) 2017-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     media_libva_caps.cpp
24 //! \brief    This file implements the base C++ class/interface for media capbilities.
25 //!
26 
27 #include "hwinfo_linux.h"
28 #include "linux_system_info.h"
29 #include "media_libva_util.h"
30 #include "media_libva_vp.h"
31 #include "media_libva_common.h"
32 #include "media_libva_caps.h"
33 #include "media_libva_caps_cp_interface.h"
34 #include "media_ddi_decode_const.h"
35 #include "media_ddi_encode_const.h"
36 #include "media_ddi_prot.h"
37 #include "media_libva_caps_factory.h"
38 #include "drm_fourcc.h"
39 
40 typedef MediaLibvaCapsFactory<MediaLibvaCaps, DDI_MEDIA_CONTEXT> CapsFactory;
41 
42 #ifdef ANDROID
43 #include <va/va_android.h>
44 #endif
45 
46 #include "set"
47 
48 #ifndef VA_ENCRYPTION_TYPE_NONE
49 #define VA_ENCRYPTION_TYPE_NONE 0x00000000
50 #endif
51 
52 
53 const uint32_t MediaLibvaCaps::m_decSliceMode[2] =
54 {
55     VA_DEC_SLICE_MODE_NORMAL,
56     VA_DEC_SLICE_MODE_BASE
57 };
58 
59 const uint32_t MediaLibvaCaps::m_decProcessMode[2] =
60 {
61     VA_DEC_PROCESSING_NONE,
62     VA_DEC_PROCESSING
63 };
64 
65 const uint32_t MediaLibvaCaps::m_encRcMode[m_numEncRcMode] =
66 {
67     VA_RC_CQP, VA_RC_CBR, VA_RC_VBR,
68     VA_RC_CBR | VA_RC_MB, VA_RC_VBR | VA_RC_MB,
69     VA_RC_ICQ, VA_RC_VCM, VA_RC_QVBR, VA_RC_AVBR
70 #if VA_CHECK_VERSION(1, 10, 0)
71     , VA_RC_TCBRC
72 #endif
73 };
74 
75 const uint32_t MediaLibvaCaps::m_vpSurfaceAttr[m_numVpSurfaceAttr] =
76 {
77     VA_FOURCC('I', '4', '2', '0'),
78     VA_FOURCC('Y', 'V', '1', '2'),
79     VA_FOURCC('Y', 'U', 'Y', '2'),
80     VA_FOURCC('4', '2', '2', 'H'),
81     VA_FOURCC('4', '2', '2', 'V'),
82     VA_FOURCC('R', 'G', 'B', 'A'),
83     VA_FOURCC('B', 'G', 'R', 'A'),
84     VA_FOURCC('R', 'G', 'B', 'P'),
85     VA_FOURCC('R', 'G', 'B', 'X'),
86     VA_FOURCC('P', '0', '1', '0'),
87     VA_FOURCC('R', 'G', '2', '4'),
88     VA_FOURCC_ARGB,
89     VA_FOURCC_ABGR,
90     VA_FOURCC_A2R10G10B10,
91     VA_FOURCC_A2B10G10R10,
92     VA_FOURCC_X2R10G10B10,
93     VA_FOURCC_X2B10G10R10,
94     VA_FOURCC_AYUV,
95     VA_FOURCC_Y210,
96     VA_FOURCC_Y410
97 };
98 
99 const uint32_t MediaLibvaCaps::m_jpegSurfaceAttr[m_numJpegSurfaceAttr] =
100 {
101     VA_FOURCC_NV12,
102     VA_FOURCC_IMC3,
103     VA_FOURCC_Y800,
104     VA_FOURCC_411P,
105     VA_FOURCC_422H,
106     VA_FOURCC_422V,
107     VA_FOURCC_444P
108 };
109 
110 const uint32_t MediaLibvaCaps::m_jpegEncSurfaceAttr[m_numJpegEncSurfaceAttr] =
111 {
112     VA_FOURCC_NV12,
113     VA_FOURCC_YUY2,
114     VA_FOURCC_UYVY,
115     VA_FOURCC_Y800
116 };
117 
MediaLibvaCaps(DDI_MEDIA_CONTEXT * mediaCtx)118 MediaLibvaCaps::MediaLibvaCaps(DDI_MEDIA_CONTEXT *mediaCtx)
119 {
120     m_mediaCtx = mediaCtx;
121     m_CapsCp = Create_MediaLibvaCapsCpInterface(mediaCtx, this);
122     if (m_CapsCp)
123     {
124         m_isEntryptSupported = m_CapsCp->IsDecEncryptionSupported(m_mediaCtx);
125     }
126 }
127 
~MediaLibvaCaps()128 MediaLibvaCaps::~MediaLibvaCaps()
129 {
130     FreeAttributeList();
131     Delete_MediaLibvaCapsCpInterface(m_CapsCp);
132     m_CapsCp = nullptr;
133 }
134 
CheckEntrypointCodecType(VAEntrypoint entrypoint,CodecType codecType)135 bool MediaLibvaCaps::CheckEntrypointCodecType(VAEntrypoint entrypoint, CodecType codecType)
136 {
137     switch (codecType)
138     {
139         case videoEncode:
140             if((entrypoint == VAEntrypointEncSlice)
141                     || (entrypoint == VAEntrypointEncSliceLP)
142                     || (entrypoint == VAEntrypointEncPicture)
143                     || (entrypoint == VAEntrypointFEI)
144                     || (entrypoint == VAEntrypointStats))
145             {
146                 return true;
147             }
148             else
149             {
150                 return false;
151             }
152             break;
153         case videoDecode:
154             return (entrypoint == VAEntrypointVLD);
155         case videoProcess:
156             if(entrypoint == VAEntrypointVideoProc)
157             {
158                 return true;
159             }
160             else
161             {
162                 return false;
163             }
164             break;
165         case videoProtect:
166             {
167                 DdiMediaProtected *prot = DdiMediaProtected::GetInstance(DDI_PROTECTED_CONTENT);
168                 if (prot && prot->CheckEntrypointSupported(entrypoint))
169                 {
170                     return true;
171                 }
172                 return false;
173             }
174             break;
175         default:
176             DDI_ASSERTMESSAGE("DDI: Unsupported codecType");
177             return false;
178     }
179 }
180 
AddDecConfig(uint32_t slicemode,uint32_t encryptType,uint32_t processType)181 VAStatus MediaLibvaCaps::AddDecConfig(uint32_t slicemode, uint32_t encryptType, uint32_t processType)
182 {
183     m_decConfigs.emplace_back(slicemode, encryptType, processType);
184     return VA_STATUS_SUCCESS;
185 }
186 
AddEncConfig(uint32_t rcMode,uint32_t feiFunction)187 VAStatus MediaLibvaCaps::AddEncConfig(uint32_t rcMode, uint32_t feiFunction)
188 {
189     m_encConfigs.emplace_back(rcMode, feiFunction);
190     return VA_STATUS_SUCCESS;
191 }
192 
AddVpConfig(uint32_t attrib)193 VAStatus MediaLibvaCaps::AddVpConfig(uint32_t attrib)
194 {
195     m_vpConfigs.emplace_back(attrib);
196     return VA_STATUS_SUCCESS;
197 }
198 
GetProfileEntrypointFromConfigId(VAConfigID configId,VAProfile * profile,VAEntrypoint * entrypoint,int32_t * profileTableIdx)199 VAStatus MediaLibvaCaps::GetProfileEntrypointFromConfigId(
200         VAConfigID configId,
201         VAProfile *profile,
202         VAEntrypoint *entrypoint,
203         int32_t *profileTableIdx)
204 {
205     DDI_CHK_NULL(profile, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
206     DDI_CHK_NULL(entrypoint, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
207     DDI_CHK_NULL(profileTableIdx, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
208     CodecType codecType;
209 
210     int32_t configOffset = 0;
211     if((configId < (DDI_CODEC_GEN_CONFIG_ATTRIBUTES_DEC_BASE + m_decConfigs.size())) )
212     {
213         configOffset = configId - DDI_CODEC_GEN_CONFIG_ATTRIBUTES_DEC_BASE;
214         codecType = videoDecode;
215     }
216     else if( (configId >= DDI_CODEC_GEN_CONFIG_ATTRIBUTES_ENC_BASE) && (configId < (DDI_CODEC_GEN_CONFIG_ATTRIBUTES_ENC_BASE + m_encConfigs.size())) )
217     {
218         configOffset = configId - DDI_CODEC_GEN_CONFIG_ATTRIBUTES_ENC_BASE;
219         codecType = videoEncode;
220     }
221     else if( (configId >= DDI_VP_GEN_CONFIG_ATTRIBUTES_BASE) && (configId < (DDI_VP_GEN_CONFIG_ATTRIBUTES_BASE + m_vpConfigs.size())))
222     {
223         configOffset = configId - DDI_VP_GEN_CONFIG_ATTRIBUTES_BASE;
224         codecType = videoProcess;
225     }
226     else if( m_CapsCp->IsCpConfigId(configId) )
227     {
228         configOffset = configId - DDI_CP_GEN_CONFIG_ATTRIBUTES_BASE;
229         codecType = videoProtect;
230     }
231     else
232     {
233         return VA_STATUS_ERROR_INVALID_CONFIG;
234     }
235 
236     int32_t i;
237     for (i = 0; i < m_profileEntryCount; i++)
238     {
239         if (CheckEntrypointCodecType(m_profileEntryTbl[i].m_entrypoint, codecType))
240         {
241             int32_t configStart = m_profileEntryTbl[i].m_configStartIdx;
242             int32_t configEnd = m_profileEntryTbl[i].m_configStartIdx + m_profileEntryTbl[i].m_configNum;
243             if (configOffset >= configStart && configOffset < configEnd)
244             {
245                 break;
246             }
247         }
248     }
249 
250     if (i == m_profileEntryCount)
251     {
252         return VA_STATUS_ERROR_INVALID_CONFIG;
253     }
254     else
255     {
256         *entrypoint  = m_profileEntryTbl[i].m_entrypoint;
257         *profile = m_profileEntryTbl[i].m_profile;
258         *profileTableIdx = i;
259     }
260     return VA_STATUS_SUCCESS;
261 }
262 
AddProfileEntry(VAProfile profile,VAEntrypoint entrypoint,AttribMap * attributeList,int32_t configStartIdx,int32_t configNum)263 VAStatus MediaLibvaCaps::AddProfileEntry(
264         VAProfile profile,
265         VAEntrypoint entrypoint,
266         AttribMap *attributeList,
267         int32_t configStartIdx,
268         int32_t configNum)
269 {
270     if (m_profileEntryCount >= m_maxProfileEntries)
271     {
272         DDI_ASSERTMESSAGE("Invalid profile entrypoint number");
273         return VA_STATUS_ERROR_INVALID_PARAMETER;
274     }
275     m_profileEntryTbl[m_profileEntryCount].m_profile = profile;
276     m_profileEntryTbl[m_profileEntryCount].m_entrypoint = entrypoint;
277     m_profileEntryTbl[m_profileEntryCount].m_attributes = attributeList;
278     m_profileEntryTbl[m_profileEntryCount].m_configStartIdx = configStartIdx;
279     m_profileEntryTbl[m_profileEntryCount].m_configNum = configNum;
280     m_profileEntryCount++;
281 
282     return VA_STATUS_SUCCESS;
283 }
284 
GetProfileTableIdx(VAProfile profile,VAEntrypoint entrypoint)285 int32_t MediaLibvaCaps::GetProfileTableIdx(VAProfile profile, VAEntrypoint entrypoint)
286 {
287     // initialize ret value to "invalid profile"
288     int32_t ret = -1;
289     for (int32_t i = 0; i < m_profileEntryCount; i++)
290     {
291         if (m_profileEntryTbl[i].m_profile == profile)
292         {
293             //there are such profile , but no such entrypoint
294             ret = -2;
295             if(m_profileEntryTbl[i].m_entrypoint == entrypoint)
296             {
297                 return i;
298             }
299         }
300     }
301 
302     return ret;
303 }
304 
CreateAttributeList(AttribMap ** attributeList)305 VAStatus MediaLibvaCaps::CreateAttributeList(AttribMap **attributeList)
306 {
307     DDI_CHK_NULL(attributeList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
308 
309     *attributeList = MOS_New(AttribMap);
310     DDI_CHK_NULL(*attributeList, "Null pointer", VA_STATUS_ERROR_ALLOCATION_FAILED);
311     m_attributeLists.push_back(*attributeList);
312 
313     return VA_STATUS_SUCCESS;
314 }
315 
GetAttributeIndex(std::vector<VAConfigAttrib> * attribList,VAConfigAttribType type)316 int32_t MediaLibvaCaps::GetAttributeIndex(std::vector<VAConfigAttrib> *attribList, VAConfigAttribType type)
317 {
318     DDI_CHK_NULL(attribList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
319     uint32_t attribSize = attribList->size();
320     for (uint32_t i = 0; i < attribSize; i++)
321     {
322         if ((*attribList)[i].type == type)
323         {
324             return i;
325         }
326     }
327     return -1;
328 
329 }
330 
SetAttribute(std::vector<VAConfigAttrib> * attributeList,VAConfigAttribType type,uint32_t value)331 VAStatus MediaLibvaCaps::SetAttribute(
332         std::vector<VAConfigAttrib> *attributeList,
333         VAConfigAttribType type,
334         uint32_t value)
335 {
336     DDI_CHK_NULL(attributeList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
337     int32_t index = GetAttributeIndex(attributeList, type);
338     if (index >= 0)
339     {
340         (*attributeList)[index].value = value;
341         return VA_STATUS_SUCCESS;
342     }
343     else
344     {
345         return VA_STATUS_ERROR_INVALID_PARAMETER;
346     }
347 }
348 
SetAttribute(VAProfile profile,VAEntrypoint entrypoint,VAConfigAttribType type,uint32_t value)349 VAStatus MediaLibvaCaps::SetAttribute(
350         VAProfile profile,
351         VAEntrypoint entrypoint,
352         VAConfigAttribType type,
353         uint32_t value)
354 {
355     int32_t idx = GetProfileTableIdx(profile, entrypoint);
356     DDI_CHK_LARGER(idx, -1, "Didn't find the profile table", VA_STATUS_ERROR_INVALID_PARAMETER);
357 
358     auto attribList = m_profileEntryTbl[idx].m_attributes;
359     DDI_CHK_NULL(attribList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
360 
361     (*attribList)[type] = value;
362     return VA_STATUS_SUCCESS;
363 }
364 
FreeAttributeList()365 VAStatus MediaLibvaCaps::FreeAttributeList()
366 {
367     uint32_t attribListCount = m_attributeLists.size();
368     for (uint32_t i = 0; i < attribListCount; i++)
369     {
370         m_attributeLists[i]->clear();
371         MOS_Delete(m_attributeLists[i]);
372         m_attributeLists[i] = nullptr;
373     }
374     m_attributeLists.clear();
375     return VA_STATUS_SUCCESS;
376 }
377 
CheckEncRTFormat(VAProfile profile,VAEntrypoint entrypoint,VAConfigAttrib * attrib)378 VAStatus MediaLibvaCaps::CheckEncRTFormat(
379         VAProfile profile,
380         VAEntrypoint entrypoint,
381         VAConfigAttrib* attrib)
382 {
383     DDI_CHK_NULL(attrib, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
384 
385     attrib->type = VAConfigAttribRTFormat;
386     if (profile == VAProfileJPEGBaseline)
387     {
388         attrib->value = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_YUV444 | VA_RT_FORMAT_YUV400 | VA_RT_FORMAT_YUV411 | VA_RT_FORMAT_RGB16 | VA_RT_FORMAT_RGB32;
389     }
390     else if(profile == VAProfileHEVCMain10 || profile == VAProfileHEVCSccMain10)
391     {
392         attrib->value = VA_RT_FORMAT_YUV420_10;
393     }
394     else if(profile == VAProfileHEVCMain12)
395     {
396         attrib->value = VA_RT_FORMAT_YUV420_12;
397     }
398     else if(profile == VAProfileHEVCMain422_10)
399     {
400         attrib->value = VA_RT_FORMAT_YUV422_10;
401     }
402     else if(profile == VAProfileHEVCMain422_12)
403     {
404         attrib->value = VA_RT_FORMAT_YUV422_12;
405     }
406     else if(profile == VAProfileHEVCMain444 || profile == VAProfileHEVCSccMain444)
407     {
408         attrib->value = VA_RT_FORMAT_YUV444;
409     }
410     else if(profile == VAProfileHEVCMain444_10 || profile == VAProfileHEVCSccMain444_10)
411     {
412         attrib->value = VA_RT_FORMAT_YUV444_10;
413     }
414     else
415     {
416         attrib->value = VA_RT_FORMAT_YUV420;
417     }
418 
419     EncodeFormat format = Others;
420     EncodeType type = entrypoint == VAEntrypointEncSliceLP ? Vdenc : DualPipe;
421     struct EncodeFormatTable* encodeFormatTable = m_encodeFormatTable;
422 
423     if(IsAvcProfile(profile))
424     {
425         format = AVC;
426     }
427     else if(IsHevcProfile(profile))
428     {
429         format = HEVC;
430     }
431     else if(IsVp9Profile(profile))
432     {
433         format = VP9;
434     }
435 
436     for(uint32_t i = 0; i < m_encodeFormatCount && encodeFormatTable != nullptr; encodeFormatTable++, i++)
437     {
438         if(encodeFormatTable->encodeFormat == format
439         && encodeFormatTable->encodeType == type)
440         {
441             attrib->value = encodeFormatTable->colorFormat;
442             break;
443         }
444     }
445 
446     return VA_STATUS_SUCCESS;
447 }
448 
CheckAttribList(VAProfile profile,VAEntrypoint entrypoint,VAConfigAttrib * attrib,int32_t numAttribs)449 VAStatus MediaLibvaCaps::CheckAttribList(
450             VAProfile profile,
451             VAEntrypoint entrypoint,
452             VAConfigAttrib* attrib,
453             int32_t numAttribs)
454 {
455     int32_t idx = GetProfileTableIdx(profile, entrypoint);
456     if(idx < 0)
457     {
458         return VA_STATUS_ERROR_INVALID_VALUE;
459     }
460 
461     DdiMediaProtected *prot = DdiMediaProtected::GetInstance(DDI_PROTECTED_CONTENT);
462     if (prot &&
463         prot->CheckEntrypointSupported(entrypoint) &&
464         prot->CheckAttribList(profile, entrypoint, attrib, numAttribs))
465     {
466         return VA_STATUS_SUCCESS;
467     }
468 
469     for(int32_t j = 0; j < numAttribs; j ++)
470     {
471         bool isValidAttrib = false;
472 
473         //temp solution for MV tools, after tool change, it should be removed
474         if(attrib[j].type == VAConfigAttribEncDynamicScaling
475           ||attrib[j].type == VAConfigAttribEncRateControlExt
476           ||attrib[j].type == VAConfigAttribEncTileSupport)
477         {
478             if(attrib[j].value == VA_ATTRIB_NOT_SUPPORTED)
479             {
480                 isValidAttrib = true;
481                 continue;
482             }
483         }
484 
485         if (m_profileEntryTbl[idx].m_attributes->find(attrib[j].type) !=
486             m_profileEntryTbl[idx].m_attributes->end())
487         {
488             isValidAttrib = false;
489 
490             if(attrib[j].value == m_configAttribNone)
491             {
492                 isValidAttrib = true;
493                 continue;
494             }
495             if(attrib[j].type == VAConfigAttribRTFormat
496              ||attrib[j].type == VAConfigAttribDecSliceMode
497              ||attrib[j].type == VAConfigAttribDecJPEG
498              ||attrib[j].type == VAConfigAttribRateControl
499              ||attrib[j].type == VAConfigAttribEncPackedHeaders
500              ||attrib[j].type == VAConfigAttribEncIntraRefresh
501              ||attrib[j].type == VAConfigAttribFEIFunctionType
502              ||attrib[j].type == VAConfigAttribEncryption)
503             {
504                 if(((*m_profileEntryTbl[idx].m_attributes)[attrib[j].type] & attrib[j].value) == attrib[j].value)
505                 {
506                     isValidAttrib = true;
507                     continue;
508                 }
509                 else if(attrib[j].type == VAConfigAttribRTFormat)
510                 {
511                     return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
512                 }
513             }
514             else if((*m_profileEntryTbl[idx].m_attributes)[attrib[j].type] == attrib[j].value)
515             {
516                 isValidAttrib = true;
517                 continue;
518             }
519             else if(attrib[j].type == VAConfigAttribEncSliceStructure)
520             {
521                 if(((*m_profileEntryTbl[idx].m_attributes)[attrib[j].type] & attrib[j].value) == attrib[j].value)
522                 {
523                     isValidAttrib = true;
524                     continue;
525                 }
526 
527                 if((*m_profileEntryTbl[idx].m_attributes)[attrib[j].type] & VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS)
528                 {
529                     if((attrib[j].value & VA_ENC_SLICE_STRUCTURE_EQUAL_ROWS)
530                        ||(attrib[j].value & VA_ENC_SLICE_STRUCTURE_EQUAL_MULTI_ROWS)
531                        ||(attrib[j].value & VA_ENC_SLICE_STRUCTURE_POWER_OF_TWO_ROWS)
532                        ||(attrib[j].value & VA_ENC_SLICE_STRUCTURE_ARBITRARY_ROWS))
533                     {
534                         isValidAttrib = true;
535                         continue;
536                     }
537                 }
538                 else if ((*m_profileEntryTbl[idx].m_attributes)[attrib[j].type] &
539                          (VA_ENC_SLICE_STRUCTURE_EQUAL_ROWS | VA_ENC_SLICE_STRUCTURE_MAX_SLICE_SIZE))
540                 {
541                     if((attrib[j].value & VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS)
542                        ||(attrib[j].value & VA_ENC_SLICE_STRUCTURE_POWER_OF_TWO_ROWS)
543                        ||(attrib[j].value & VA_ENC_SLICE_STRUCTURE_ARBITRARY_ROWS))
544                     {
545                         isValidAttrib = true;
546                         continue;
547                     }
548                 }
549             }
550             else if((attrib[j].type == VAConfigAttribMaxPictureWidth)
551                  || (attrib[j].type == VAConfigAttribMaxPictureHeight)
552                  || (attrib[j].type == VAConfigAttribEncROI)
553                  || (attrib[j].type == VAConfigAttribEncDirtyRect))
554             {
555                 if(attrib[j].value <= (*m_profileEntryTbl[idx].m_attributes)[attrib[j].type])
556                 {
557                     isValidAttrib = true;
558                     continue;
559                 }
560             }
561             else if(attrib[j].type == VAConfigAttribEncMaxRefFrames)
562             {
563                 if(((attrib[j].value & 0xffff) <= ((*m_profileEntryTbl[idx].m_attributes)[attrib[j].type] & 0xffff))
564                  &&(attrib[j].value <= (*m_profileEntryTbl[idx].m_attributes)[attrib[j].type]))  //high16 bit  can compare with this way
565                 {
566                     isValidAttrib = true;
567                     continue;
568                 }
569             }
570             else if(attrib[j].type == VAConfigAttribEncJPEG)
571             {
572                 VAConfigAttribValEncJPEG jpegValue, jpegSetValue;
573                 jpegValue.value = attrib[j].value;
574                 jpegSetValue.value = (*m_profileEntryTbl[idx].m_attributes)[attrib[j].type];
575                 if((jpegValue.bits.max_num_quantization_tables <= jpegSetValue.bits.max_num_quantization_tables)
576                    &&(jpegValue.bits.max_num_huffman_tables <= jpegSetValue.bits.max_num_huffman_tables)
577                    &&(jpegValue.bits.max_num_scans <= jpegSetValue.bits.max_num_scans)
578                    &&(jpegValue.bits.max_num_components <= jpegSetValue.bits.max_num_components))
579                 {
580                     isValidAttrib = true;
581                     continue;
582                 }
583             }
584 
585         }
586         //should be removed after msdk remove VAConfigAttribSpatialResidual attributes for VPP
587         else if((profile == VAProfileNone)
588                && (entrypoint == VAEntrypointVideoProc)
589                && (attrib[j].type == VAConfigAttribSpatialClipping))
590         {
591             isValidAttrib = true;
592             continue;
593         }
594         else if((profile == VAProfileNone)
595                && (attrib[j].type == VAConfigAttribStats))
596         {
597             isValidAttrib = true;
598             continue;
599         }
600 
601         if(!isValidAttrib)
602         {
603            return VA_STATUS_ERROR_INVALID_VALUE;
604         }
605     }
606     return VA_STATUS_SUCCESS;
607 }
608 
GetGeneralConfigAttrib(VAConfigAttrib * attrib)609 VAStatus MediaLibvaCaps::GetGeneralConfigAttrib(VAConfigAttrib* attrib)
610 {
611     DDI_CHK_NULL(attrib, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
612 
613     VAStatus status = VA_STATUS_SUCCESS;
614 #if VA_CHECK_VERSION(1, 10, 0)
615     if (attrib->type == VAConfigAttribContextPriority)
616     {
617         attrib->value = CONTEXT_PRIORITY_MAX;
618     }
619     else
620 #endif
621     {
622         status = VA_ATTRIB_NOT_SUPPORTED;
623     }
624     return status;
625 }
626 
CreateEncAttributes(VAProfile profile,VAEntrypoint entrypoint,AttribMap ** attributeList)627 VAStatus MediaLibvaCaps::CreateEncAttributes(
628         VAProfile profile,
629         VAEntrypoint entrypoint,
630         AttribMap **attributeList)
631 {
632     DDI_CHK_NULL(attributeList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
633 
634     VAStatus status = CreateAttributeList(attributeList);
635     DDI_CHK_RET(status, "Failed to initialize Caps!");
636 
637     auto attribList = *attributeList;
638     DDI_CHK_NULL(attribList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
639 
640     VAConfigAttrib attrib;
641     attrib.type = VAConfigAttribRTFormat;
642     status = CheckEncRTFormat(profile, entrypoint, &attrib);
643     DDI_CHK_RET(status, "Failed to Check Encode RT Format!");
644     (*attribList)[attrib.type] = attrib.value;
645 
646     attrib.type = VAConfigAttribMaxPictureWidth;
647     GetPlatformSpecificAttrib(profile, entrypoint,
648         VAConfigAttribMaxPictureWidth, &attrib.value);
649     if(IsMpeg2Profile(profile))
650     {
651         attrib.value = CODEC_2K_MAX_PIC_WIDTH;
652     }
653     (*attribList)[attrib.type] = attrib.value;
654 
655     attrib.type = VAConfigAttribMaxPictureHeight;
656     GetPlatformSpecificAttrib(profile, entrypoint,
657         VAConfigAttribMaxPictureHeight, &attrib.value);
658     if(IsMpeg2Profile(profile))
659     {
660         attrib.value = CODEC_2K_MAX_PIC_HEIGHT;
661     }
662     (*attribList)[attrib.type] = attrib.value;
663 
664     attrib.type = VAConfigAttribEncJPEG;
665     VAConfigAttribValEncJPEG jpegAttribVal;
666     jpegAttribVal.bits.arithmatic_coding_mode = 0;
667     jpegAttribVal.bits.progressive_dct_mode = 0;
668     jpegAttribVal.bits.non_interleaved_mode = 0;
669     jpegAttribVal.bits.differential_mode = 0;
670     jpegAttribVal.bits.max_num_components = jpegNumComponent;
671     jpegAttribVal.bits.max_num_scans = 1;
672     jpegAttribVal.bits.max_num_huffman_tables = JPEG_MAX_NUM_HUFF_TABLE_INDEX;
673     jpegAttribVal.bits.max_num_quantization_tables = JPEG_MAX_QUANT_TABLE;
674     attrib.value = jpegAttribVal.value;
675     (*attribList)[attrib.type] = attrib.value;
676 
677     attrib.type = VAConfigAttribEncQualityRange;
678     if (profile == VAProfileJPEGBaseline)
679     {
680         // JPEG has no target usage.
681         attrib.value = 1;
682     }
683     else
684     {
685         attrib.value = NUM_TARGET_USAGE_MODES - 1;// Indicates TUs from 1 upto the value reported are supported
686     }
687     (*attribList)[attrib.type] = attrib.value;
688 
689     attrib.type = VAConfigAttribEncPackedHeaders;
690     attrib.value = VA_ATTRIB_NOT_SUPPORTED;
691     if ((IsAvcProfile(profile))||(IsHevcProfile(profile)))
692     {
693         attrib.value = VA_ENC_PACKED_HEADER_PICTURE    |
694             VA_ENC_PACKED_HEADER_SEQUENCE   |
695             VA_ENC_PACKED_HEADER_SLICE      |
696             VA_ENC_PACKED_HEADER_RAW_DATA   |
697             VA_ENC_PACKED_HEADER_MISC;
698     }
699     else if (IsMpeg2Profile(profile))
700     {
701         attrib.value = VA_ENC_PACKED_HEADER_RAW_DATA;
702     }
703     else if(IsJpegProfile(profile))
704     {
705         attrib.value = VA_ENC_PACKED_HEADER_RAW_DATA;
706     }
707     else if(IsVp9Profile(profile))
708     {
709         attrib.value = VA_ENC_PACKED_HEADER_RAW_DATA;
710     }
711     else if(IsVp8Profile(profile))
712     {
713         attrib.value = VA_ENC_PACKED_HEADER_NONE;
714     }
715 
716     (*attribList)[attrib.type] = attrib.value;
717     if(IsJpegProfile(profile))
718     {
719         return status;
720     }
721 
722     attrib.type = VAConfigAttribRateControl;
723     attrib.value = VA_RC_CQP;
724     if (entrypoint != VAEntrypointEncSliceLP ||
725             (entrypoint == VAEntrypointEncSliceLP && MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEnableMediaKernels)))
726     {
727         attrib.value |= VA_RC_CBR | VA_RC_VBR | VA_RC_MB;
728 
729         if (IsHevcProfile(profile))
730         {
731             if (entrypoint != VAEntrypointEncSliceLP)
732                 attrib.value |= VA_RC_ICQ | VA_RC_QVBR;
733 
734             attrib.value |= VA_RC_VCM;
735         }
736     }
737     if (IsAvcProfile(profile) && (entrypoint != VAEntrypointEncSliceLP))
738     {
739         attrib.value |= VA_RC_ICQ | VA_RC_VCM | VA_RC_QVBR | VA_RC_AVBR;
740     }
741     if (IsAvcProfile(profile) &&
742             ((entrypoint == VAEntrypointEncSliceLP) && MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEnableMediaKernels)))
743     {
744         attrib.value |= VA_RC_QVBR;
745     }
746     if(entrypoint == VAEntrypointFEI)
747     {
748         attrib.value = VA_RC_CQP;
749     }
750     else if(entrypoint == VAEntrypointStats)
751     {
752         attrib.value = VA_RC_NONE;
753     }
754     (*attribList)[attrib.type] = attrib.value;
755 
756     attrib.type = VAConfigAttribEncInterlaced;
757     attrib.value = VA_ENC_INTERLACED_NONE;
758 #ifndef ANDROID
759     if(IsAvcProfile(profile) && (entrypoint != VAEntrypointEncSliceLP))
760     {
761         attrib.value = VA_ENC_INTERLACED_FIELD;
762     }
763     if(IsMpeg2Profile(profile))
764     {
765         attrib.value = VA_ENC_INTERLACED_FRAME;
766     }
767 #endif
768     (*attribList)[attrib.type] = attrib.value;
769 
770     attrib.type = VAConfigAttribEncMaxRefFrames;
771     if (entrypoint == VAEntrypointEncSliceLP)
772     {
773         //VDEnc Low delay P
774         attrib.value = DDI_CODEC_VDENC_MAX_L0_REF_FRAMES | (DDI_CODEC_VDENC_MAX_L1_REF_FRAMES << DDI_CODEC_LEFT_SHIFT_FOR_REFLIST1);
775         if(IsHevcProfile(profile))
776         {
777             //VDEnc Low Delay B, for B frame, it should be 3, 1 instead of this value, but libva could distinguish it with different frame type now
778             attrib.value = DDI_CODEC_VDENC_MAX_L0_REF_FRAMES_LDB | (DDI_CODEC_VDENC_MAX_L1_REF_FRAMES_LDB << DDI_CODEC_LEFT_SHIFT_FOR_REFLIST1);
779         }
780     }
781     else
782     {
783         // default value: 1 frame for each reference list
784         attrib.value = 1 | (1 << 16);
785         if(IsAvcProfile(profile))
786         {
787             attrib.value = CODECHAL_ENCODE_NUM_MAX_VME_L0_REF | (CODECHAL_ENCODE_NUM_MAX_VME_L1_REF << 16);
788         }
789         if(IsVp8Profile(profile))
790         {
791             attrib.value = ENCODE_VP8_NUM_MAX_L0_REF ;
792         }
793         if(IsVp9Profile(profile))
794         {
795             attrib.value = ENCODE_VP9_NUM_MAX_L0_REF;
796         }
797         if (IsHevcProfile(profile))
798         {
799             GetPlatformSpecificAttrib(profile, entrypoint,
800                     VAConfigAttribEncMaxRefFrames, &attrib.value);
801         }
802     }
803     (*attribList)[attrib.type] = attrib.value;
804 
805     attrib.type = VAConfigAttribEncMaxSlices;
806     if (entrypoint == VAEntrypointEncSliceLP)
807     {
808         if (IsAvcProfile(profile))
809         {
810             attrib.value = ENCODE_AVC_MAX_SLICES_SUPPORTED;
811         }
812         else if (IsHevcProfile(profile))
813         {
814             attrib.value = ENCODE_HEVC_VDENC_NUM_MAX_SLICES;
815         }
816     }
817     else
818     {
819         attrib.value = 0;
820         if (IsAvcProfile(profile))
821         {
822             attrib.value = ENCODE_AVC_MAX_SLICES_SUPPORTED;
823         }
824         else if (IsHevcProfile(profile))
825         {
826             GetPlatformSpecificAttrib(profile, entrypoint,
827                     VAConfigAttribEncMaxSlices, &attrib.value);
828         }
829     }
830     (*attribList)[attrib.type] = attrib.value;
831 
832     attrib.type = VAConfigAttribEncSliceStructure;
833     if (entrypoint == VAEntrypointEncSliceLP)
834     {
835         attrib.value = VA_ENC_SLICE_STRUCTURE_EQUAL_ROWS | VA_ENC_SLICE_STRUCTURE_EQUAL_MULTI_ROWS
836             | VA_ENC_SLICE_STRUCTURE_MAX_SLICE_SIZE;
837     }
838     else
839     {
840         attrib.value = VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS;
841     }
842     (*attribList)[attrib.type] = attrib.value;
843 
844     attrib.type = VAConfigAttribEncQuantization;
845     if(IsAvcProfile(profile))
846     {
847         attrib.value = VA_ENC_QUANTIZATION_TRELLIS_SUPPORTED;
848     }
849     else
850     {
851         attrib.value = VA_ENC_QUANTIZATION_NONE;
852     }
853     (*attribList)[attrib.type] = attrib.value;
854 
855     attrib.type = VAConfigAttribEncIntraRefresh;
856     attrib.value = VA_ENC_INTRA_REFRESH_NONE;
857     GetPlatformSpecificAttrib(profile, entrypoint,
858         VAConfigAttribEncIntraRefresh, &attrib.value);
859     (*attribList)[attrib.type] = attrib.value;
860 
861     attrib.type = VAConfigAttribEncSkipFrame;
862     if (entrypoint == VAEntrypointEncSliceLP)
863     {
864         if (IsAvcProfile(profile))
865         {
866             attrib.value = 1;
867         }
868         else
869         {
870             attrib.value = 0;
871         }
872     }
873     else
874     {
875         attrib.value = 1;
876     }
877     (*attribList)[attrib.type] = attrib.value;
878 
879     attrib.type = VAConfigAttribEncryption;
880     attrib.value = VA_ATTRIB_NOT_SUPPORTED;
881     if (m_isEntryptSupported)
882     {
883         attrib.value = 0;
884         uint32_t encryptTypes[DDI_CP_ENCRYPT_TYPES_NUM] = {0};
885         int32_t  numTypes =  m_CapsCp->GetEncryptionTypes(profile,
886                  encryptTypes, DDI_CP_ENCRYPT_TYPES_NUM);
887         if (numTypes > 0)
888         {
889             for (int32_t j = 0; j < numTypes; j++)
890             {
891                 attrib.value |= encryptTypes[j];
892             }
893         }
894     }
895     (*attribList)[attrib.type] = attrib.value;
896 
897     attrib.type = VAConfigAttribEncROI;
898     if (entrypoint == VAEntrypointEncSliceLP)
899     {
900         VAConfigAttribValEncROI roi_attrib = {0};
901         if (IsAvcProfile(profile))
902         {
903             roi_attrib.bits.num_roi_regions = ENCODE_VDENC_AVC_MAX_ROI_NUMBER_G9;
904         }
905         else if (IsHevcProfile(profile))
906         {
907             roi_attrib.bits.num_roi_regions = CODECHAL_ENCODE_HEVC_MAX_NUM_ROI;
908         }
909 
910         roi_attrib.bits.roi_rc_priority_support = 0;
911         roi_attrib.bits.roi_rc_qp_delta_support = 1;
912 
913         attrib.value = roi_attrib.value;
914     }
915     else
916     {
917         GetPlatformSpecificAttrib(profile, entrypoint,
918                 VAConfigAttribEncROI, &attrib.value);
919     }
920     (*attribList)[attrib.type] = attrib.value;
921 
922     attrib.type = VAConfigAttribProcessingRate;
923     attrib.value = VA_PROCESSING_RATE_ENCODE;
924     (*attribList)[attrib.type] = attrib.value;
925 
926     attrib.type = (VAConfigAttribType)VAConfigAttribEncDirtyRect;
927     attrib.value = 4;
928     (*attribList)[attrib.type] = attrib.value;
929 
930     attrib.type = VAConfigAttribEncParallelRateControl;
931     attrib.value = 1;
932     (*attribList)[attrib.type] = attrib.value;
933 
934     if ((entrypoint == VAEntrypointFEI) && (IsAvcProfile(profile) || IsHevcProfile(profile)))
935     {
936         attrib.type = (VAConfigAttribType)VAConfigAttribFEIFunctionType;
937         attrib.value = IsAvcProfile(profile) ?
938                        (VA_FEI_FUNCTION_ENC | VA_FEI_FUNCTION_PAK | VA_FEI_FUNCTION_ENC_PAK) :
939                        VA_FEI_FUNCTION_ENC_PAK;
940         (*attribList)[attrib.type] = attrib.value;
941     }
942 
943     attrib.type = (VAConfigAttribType)VAConfigAttribFEIMVPredictors;
944     attrib.value = 0;
945     if(IsAvcProfile(profile) || IsHevcProfile(profile))
946     {
947         attrib.value = DDI_CODEC_FEI_MAX_NUM_MVPREDICTOR;
948     }
949     (*attribList)[attrib.type] = attrib.value;
950 
951     if(profile == VAProfileNone)
952     {
953         attrib.type = (VAConfigAttribType)VAConfigAttribStats;
954         VAConfigAttribValStats attribValStats;
955         memset(&attribValStats, 0, sizeof(attribValStats));
956         attribValStats.bits.max_num_past_references   = DDI_CODEC_STATS_MAX_NUM_PAST_REFS;
957         attribValStats.bits.max_num_future_references = DDI_CODEC_STATS_MAX_NUM_FUTURE_REFS;
958         attribValStats.bits.num_outputs               = DDI_CODEC_STATS_MAX_NUM_OUTPUTS;
959         attribValStats.bits.interlaced                = DDI_CODEC_STATS_INTERLACED_SUPPORT;
960         attrib.value = attribValStats.value;
961         (*attribList)[attrib.type] = attrib.value;
962     }
963 
964     attrib.type = (VAConfigAttribType)VAConfigAttribCustomRoundingControl;
965     GetPlatformSpecificAttrib(profile, entrypoint,
966             (VAConfigAttribType)VAConfigAttribCustomRoundingControl, &attrib.value);
967     (*attribList)[attrib.type] = attrib.value;
968 
969     if(IsAvcProfile(profile))
970     {
971         // Use VAConfigAttribQPBlockSize to report MBQP support:
972         // >0 means supported, 0 unsupported. Previous versions of driver
973         // return VA_ATTRIB_NOT_SUPPORTED for that attribute.
974         attrib.type = VAConfigAttribQPBlockSize;
975         if(entrypoint == VAEntrypointEncSliceLP)
976         {
977             GetPlatformSpecificAttrib(profile, entrypoint,
978                                       VAConfigAttribQPBlockSize, &attrib.value);
979             if(attrib.value == VA_ATTRIB_NOT_SUPPORTED)
980             {
981                 attrib.value = 0;
982             }
983         } else
984         {
985             // MBQP always supported for VME
986             attrib.value = CODECHAL_MACROBLOCK_WIDTH;
987         }
988         (*attribList)[attrib.type] = attrib.value;
989     }
990 
991     if (IsAvcProfile(profile))
992     {
993         attrib.type = (VAConfigAttribType)VAConfigAttribMaxFrameSize;
994         VAConfigAttribValMaxFrameSize attribValMaxFrameSize;
995         memset(&attribValMaxFrameSize, 0, sizeof(attribValMaxFrameSize));
996         attribValMaxFrameSize.bits.max_frame_size = 1;
997         attribValMaxFrameSize.bits.multiple_pass  = 1;
998         attribValMaxFrameSize.bits.reserved       = 0;
999         attrib.value = attribValMaxFrameSize.value;
1000         (*attribList)[attrib.type] = attrib.value;
1001     }
1002 
1003     if (IsHevcProfile(profile))
1004     {
1005         attrib.type = (VAConfigAttribType) VAConfigAttribPredictionDirection;
1006         GetPlatformSpecificAttrib(profile, entrypoint,
1007                                       VAConfigAttribPredictionDirection, &attrib.value);
1008         (*attribList)[attrib.type] = attrib.value;
1009     }
1010     return status;
1011 }
1012 
CreateDecAttributes(VAProfile profile,VAEntrypoint entrypoint,AttribMap ** attributeList)1013 VAStatus MediaLibvaCaps::CreateDecAttributes(
1014         VAProfile profile,
1015         VAEntrypoint entrypoint,
1016         AttribMap **attributeList)
1017 {
1018     DDI_CHK_NULL(attributeList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
1019 
1020     VAStatus status = CreateAttributeList(attributeList);
1021     DDI_CHK_RET(status, "Failed to initialize Caps!");
1022 
1023     auto attribList = *attributeList;
1024     DDI_CHK_NULL(attribList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
1025 
1026     VAConfigAttrib attrib;
1027     attrib.type = VAConfigAttribRTFormat;
1028     if ( profile == VAProfileJPEGBaseline )
1029     {
1030         // at present, latest libva have not support RGB24.
1031         attrib.value = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_YUV444 | VA_RT_FORMAT_YUV400 | VA_RT_FORMAT_YUV411 | VA_RT_FORMAT_RGB16 | VA_RT_FORMAT_RGB32;
1032     }
1033     else if(profile == VAProfileHEVCMain10)
1034     {
1035         attrib.value = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV420_10;
1036     }
1037     else if(profile == VAProfileHEVCMain422_10)
1038     {
1039         attrib.value = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_YUV400 | VA_RT_FORMAT_YUV420_10 | VA_RT_FORMAT_YUV422_10;
1040     }
1041     else
1042     {
1043         attrib.value = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_RGB32;
1044     }
1045     (*attribList)[attrib.type] = attrib.value;
1046 
1047     attrib.type = VAConfigAttribDecSliceMode;
1048     if (IsAvcProfile(profile))
1049     {
1050         attrib.value = VA_DEC_SLICE_MODE_NORMAL | VA_DEC_SLICE_MODE_BASE;
1051     }
1052     else if (IsHevcProfile(profile))
1053     {
1054         bool  hevcmainProfileSupported = false;
1055         attrib.value = 0;
1056         if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLDMainDecoding)
1057                 || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLDMain10Decoding)
1058                 || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLDMain12bit420Decoding)
1059                 || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLD42210bitDecoding)
1060                 || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLDMain12bit422Decoding)
1061                 || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLD4448bitDecoding)
1062                 || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLD44410bitDecoding)
1063                 || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLDMain12bit444Decoding))
1064         {
1065             attrib.value |= VA_DEC_SLICE_MODE_NORMAL;
1066             hevcmainProfileSupported = true;
1067         }
1068         if ((MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrHEVCVLDMainShortDecoding) ||
1069                     MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrHEVCVLDMain10ShortDecoding))
1070                 && MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEnableMediaKernels))
1071         {
1072             attrib.value |= VA_DEC_SLICE_MODE_BASE;
1073             hevcmainProfileSupported = true;
1074         }
1075         if (!hevcmainProfileSupported)
1076         {
1077             attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1078         }
1079     }
1080     else if (profile == VAProfileVP9Profile0
1081           || profile == VAProfileVP9Profile2
1082           || profile == VAProfileVP9Profile1
1083           || profile == VAProfileVP9Profile3)
1084     {
1085         bool    vp9ProfileSupported = false;
1086         attrib.value = 0;
1087         if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile0Decoding8bit420)
1088              || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile1Decoding8bit444))
1089         {
1090             attrib.value |= VA_DEC_SLICE_MODE_NORMAL | VA_DEC_SLICE_MODE_BASE;
1091             vp9ProfileSupported = true;
1092         }
1093         if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrVP9VLD10bProfile2Decoding)
1094             || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile3Decoding10bit444))
1095         {
1096             attrib.value |= VA_DEC_SLICE_MODE_NORMAL;
1097             vp9ProfileSupported = true;
1098         }
1099         if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile2Decoding10bit420))
1100         {
1101             (*attribList) [VAConfigAttribRTFormat] |= VA_RT_FORMAT_YUV420_10;
1102             attrib.value |= VA_DEC_SLICE_MODE_NORMAL;
1103             vp9ProfileSupported = true;
1104         }
1105         if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile2Decoding12bit420)
1106             || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile3Decoding12bit444))
1107         {
1108             attrib.value |= VA_DEC_SLICE_MODE_NORMAL;
1109             vp9ProfileSupported = true;
1110         }
1111         if (!vp9ProfileSupported)
1112         {
1113             attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1114         }
1115         if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile1Decoding8bit444))
1116             (*attribList) [VAConfigAttribRTFormat] |= VA_RT_FORMAT_YUV444;
1117         if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrVP9VLD10bProfile2Decoding))
1118             (*attribList) [VAConfigAttribRTFormat] |= VA_RT_FORMAT_YUV420_10;
1119         if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile3Decoding10bit444))
1120             (*attribList) [VAConfigAttribRTFormat] |= VA_RT_FORMAT_YUV444_10;
1121         if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile2Decoding12bit420))
1122             (*attribList) [VAConfigAttribRTFormat] |= VA_RT_FORMAT_YUV420_12;
1123         if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile3Decoding12bit444))
1124             (*attribList) [VAConfigAttribRTFormat] |= VA_RT_FORMAT_YUV444_12;
1125     }
1126     else
1127     {
1128         attrib.value = VA_DEC_SLICE_MODE_NORMAL;
1129     }
1130     (*attribList)[attrib.type] = attrib.value;
1131 
1132     attrib.type = VAConfigAttribDecProcessing;
1133     attrib.value = VA_DEC_PROCESSING_NONE;
1134     GetPlatformSpecificAttrib(profile, entrypoint,
1135             VAConfigAttribDecProcessing, &attrib.value);
1136     (*attribList)[attrib.type] = attrib.value;
1137 
1138     attrib.type = VAConfigAttribMaxPictureWidth;
1139     attrib.value = CODEC_MAX_PIC_WIDTH;
1140     if(profile == VAProfileJPEGBaseline)
1141     {
1142         attrib.value = ENCODE_JPEG_MAX_PIC_WIDTH;
1143     }
1144     if(IsVc1Profile(profile) || IsMpeg2Profile(profile))
1145     {
1146         attrib.value = CODEC_2K_MAX_PIC_WIDTH;
1147     }
1148     if(IsVp8Profile(profile))
1149     {
1150         attrib.value = CODEC_4K_MAX_PIC_WIDTH;
1151     }
1152     if(IsAvcProfile(profile))
1153     {
1154         attrib.value = CODEC_4K_MAX_PIC_WIDTH;
1155     }
1156     if(IsHevcProfile(profile) || IsVp9Profile(profile))
1157     {
1158         attrib.value = CODEC_8K_MAX_PIC_WIDTH;
1159     }
1160     (*attribList)[attrib.type] = attrib.value;
1161 
1162     attrib.type = VAConfigAttribMaxPictureHeight;
1163     attrib.value = CODEC_MAX_PIC_HEIGHT;
1164     if(profile == VAProfileJPEGBaseline)
1165     {
1166         attrib.value = ENCODE_JPEG_MAX_PIC_HEIGHT;
1167     }
1168     if(IsVc1Profile(profile) || IsMpeg2Profile(profile))
1169     {
1170         attrib.value = CODEC_2K_MAX_PIC_HEIGHT;
1171     }
1172     if(IsVp8Profile(profile))
1173     {
1174         attrib.value = CODEC_4K_MAX_PIC_HEIGHT;
1175     }
1176     if(IsAvcProfile(profile))
1177     {
1178         attrib.value = CODEC_4K_MAX_PIC_HEIGHT;
1179     }
1180     if(IsHevcProfile(profile) || IsVp9Profile(profile))
1181     {
1182         attrib.value = CODEC_8K_MAX_PIC_HEIGHT;
1183     }
1184     (*attribList)[attrib.type] = attrib.value;
1185 
1186     attrib.type = VAConfigAttribEncryption;
1187     attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1188     if (m_isEntryptSupported)
1189     {
1190         attrib.value = 0;
1191         uint32_t encryptTypes[DDI_CP_ENCRYPT_TYPES_NUM] = {0};
1192         int32_t numTypes =  m_CapsCp->GetEncryptionTypes(profile,
1193                 encryptTypes, DDI_CP_ENCRYPT_TYPES_NUM);
1194         if (numTypes > 0)
1195         {
1196             for (int32_t j = 0; j < numTypes; j++)
1197             {
1198                 attrib.value |= encryptTypes[j];
1199             }
1200         }
1201     }
1202     (*attribList)[attrib.type] = attrib.value;
1203 
1204     if(profile == VAProfileJPEGBaseline)
1205     {
1206         attrib.type = VAConfigAttribDecJPEG;
1207         attrib.value = ((1 << VA_ROTATION_NONE) | (1 << VA_ROTATION_90) | (1 << VA_ROTATION_180) | (1 << VA_ROTATION_270));
1208         (*attribList)[attrib.type] = attrib.value;
1209     }
1210 
1211     if(profile == VAProfileNone)
1212     {
1213         attrib.type = (VAConfigAttribType)VAConfigAttribStats;
1214         VAConfigAttribValStats attribValStats;
1215         memset(&attribValStats, 0, sizeof(attribValStats));
1216         attribValStats.bits.max_num_past_references   = DDI_CODEC_STATS_MAX_NUM_PAST_REFS;
1217         attribValStats.bits.max_num_future_references = DDI_CODEC_STATS_MAX_NUM_FUTURE_REFS;
1218         attribValStats.bits.num_outputs               = DDI_CODEC_STATS_MAX_NUM_OUTPUTS;
1219         attribValStats.bits.interlaced                = DDI_CODEC_STATS_INTERLACED_SUPPORT;
1220         attrib.value = attribValStats.value;
1221         (*attribList)[attrib.type] = attrib.value;
1222     }
1223 
1224     attrib.type = VAConfigAttribProcessingRate;
1225     attrib.value = VA_PROCESSING_RATE_DECODE;
1226     (*attribList)[attrib.type] = attrib.value;
1227 
1228     attrib.type = (VAConfigAttribType)VAConfigAttribCustomRoundingControl;
1229     GetPlatformSpecificAttrib(profile, entrypoint,
1230             (VAConfigAttribType)VAConfigAttribCustomRoundingControl, &attrib.value);
1231     (*attribList)[attrib.type] = attrib.value;
1232 
1233     return status;
1234 }
1235 
CreateVpAttributes(VAProfile profile,VAEntrypoint entrypoint,AttribMap ** attributeList)1236 VAStatus MediaLibvaCaps::CreateVpAttributes(
1237         VAProfile profile,
1238         VAEntrypoint entrypoint,
1239         AttribMap **attributeList)
1240 {
1241     DDI_CHK_NULL(attributeList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
1242 
1243     VAStatus status = CreateAttributeList(attributeList);
1244     DDI_CHK_RET(status, "Failed to initialize Caps!");
1245 
1246     auto attribList = *attributeList;
1247     DDI_CHK_NULL(attribList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
1248 
1249     VAConfigAttrib attrib;
1250     attrib.type = VAConfigAttribRTFormat;
1251     attrib.value = VA_RT_FORMAT_YUV420 |
1252                    VA_RT_FORMAT_YUV422 |
1253                    VA_RT_FORMAT_YUV444 |
1254                    VA_RT_FORMAT_YUV400 |
1255                    VA_RT_FORMAT_YUV411 |
1256                    VA_RT_FORMAT_RGB16 |
1257                    VA_RT_FORMAT_RGB32;
1258 
1259     if ((m_mediaCtx->platform.eRenderCoreFamily == IGFX_GEN9_CORE) ||
1260         (m_mediaCtx->platform.eRenderCoreFamily == IGFX_GEN12_CORE))
1261     {
1262         attrib.value |= VA_RT_FORMAT_RGBP;
1263     }
1264 
1265     (*attribList)[attrib.type] = attrib.value;
1266     return status;
1267 }
1268 
LoadAvcDecProfileEntrypoints()1269 VAStatus MediaLibvaCaps::LoadAvcDecProfileEntrypoints()
1270 {
1271     VAStatus status = VA_STATUS_SUCCESS;
1272 
1273 #ifdef _AVC_DECODE_SUPPORTED
1274     AttribMap *attributeList = nullptr;
1275     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrAVCVLDLongDecoding)
1276             || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrAVCVLDShortDecoding))
1277     {
1278         status = CreateDecAttributes(VAProfileH264Main, VAEntrypointVLD, &attributeList);
1279         DDI_CHK_RET(status, "Failed to initialize Caps!");
1280 
1281         VAProfile profile[3] = {
1282             VAProfileH264Main,
1283             VAProfileH264High,
1284             VAProfileH264ConstrainedBaseline};
1285 
1286         uint32_t configStartIdx, configNum;
1287         for (int32_t i = 0; i < 3; i++)
1288         {
1289             configStartIdx = m_decConfigs.size();
1290             for (int32_t j = 0; j < 2; j++)
1291             {
1292                 for (int32_t k = 0; k < 2; k++)
1293                 {
1294                     AddDecConfig(m_decSliceMode[j], VA_ENCRYPTION_TYPE_NONE, m_decProcessMode[k]);
1295                     if (m_isEntryptSupported)
1296                     {
1297                         uint32_t encrytTypes[DDI_CP_ENCRYPT_TYPES_NUM];
1298 
1299                         int32_t numTypes = m_CapsCp->GetEncryptionTypes(profile[i],
1300                                 encrytTypes, DDI_CP_ENCRYPT_TYPES_NUM);
1301 
1302                         if (numTypes > 0)
1303                         {
1304                             for (int32_t l = 0; l < numTypes; l++)
1305                             {
1306                                 AddDecConfig(m_decSliceMode[j], encrytTypes[l],
1307                                         m_decProcessMode[k]);
1308                             }
1309                         }
1310                     }
1311                 }
1312             }
1313 
1314             configNum = m_decConfigs.size() - configStartIdx;
1315             AddProfileEntry(profile[i], VAEntrypointVLD, attributeList, configStartIdx, configNum);
1316         }
1317     }
1318 #endif
1319     return status;
1320 }
1321 
LoadAvcEncProfileEntrypoints()1322 VAStatus MediaLibvaCaps::LoadAvcEncProfileEntrypoints()
1323 {
1324     VAStatus status = VA_STATUS_SUCCESS;
1325 
1326 #if defined (_AVC_ENCODE_VME_SUPPORTED) || defined (_AVC_ENCODE_VDENC_SUPPORTED)
1327     AttribMap *attributeList = nullptr;
1328     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEncodeAVC))
1329     {
1330         status = CreateEncAttributes(VAProfileH264Main, VAEntrypointEncSlice, &attributeList);
1331         DDI_CHK_RET(status, "Failed to initialize Caps!");
1332 
1333         VAProfile profile[3] = {
1334             VAProfileH264Main,
1335             VAProfileH264High,
1336             VAProfileH264ConstrainedBaseline};
1337 
1338         VAEntrypoint entrypoint[2] = {VAEntrypointEncSlice, VAEntrypointFEI};
1339 
1340         uint32_t feiFunctions[3] = {
1341                 VA_FEI_FUNCTION_ENC,
1342                 VA_FEI_FUNCTION_PAK,
1343                 VA_FEI_FUNCTION_ENC_PAK};
1344 
1345         uint32_t configStartIdx;
1346 
1347         for (int32_t e = 0; e < 2; e++)
1348         {
1349             status = CreateEncAttributes(VAProfileH264ConstrainedBaseline, entrypoint[e], &attributeList);
1350             DDI_CHK_RET(status, "Failed to initialize Caps!");
1351 
1352             for (int32_t i = 0; i < 3; i++)
1353             {
1354                 configStartIdx = m_encConfigs.size();
1355                 bool isFei = !!(entrypoint[e] == VAEntrypointFEI);
1356                 int32_t maxRcMode = (entrypoint[e] == VAEntrypointEncSlice ? 9 : 1);
1357                 for (int32_t j = 0; j < maxRcMode; j++)
1358                 {
1359                     if (isFei)
1360                     {
1361                         for (int32_t k = 0; k < 3; k++)
1362                         {
1363                             AddEncConfig(m_encRcMode[j], feiFunctions[k]);
1364                         }
1365                     }
1366                     else
1367                         AddEncConfig(m_encRcMode[j]);
1368                 }
1369                 AddProfileEntry(profile[i], entrypoint[e], attributeList,
1370                         configStartIdx, m_encConfigs.size() - configStartIdx);
1371             }
1372         }
1373     }
1374 #endif
1375     return status;
1376 }
1377 
LoadAvcEncLpProfileEntrypoints()1378 VAStatus MediaLibvaCaps::LoadAvcEncLpProfileEntrypoints()
1379 {
1380     VAStatus status = VA_STATUS_SUCCESS;
1381 
1382 #if defined (_AVC_ENCODE_VME_SUPPORTED) || defined (_AVC_ENCODE_VDENC_SUPPORTED)
1383     AttribMap *attributeList = nullptr;
1384     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEncodeAVCVdenc))
1385     {
1386         status = CreateEncAttributes(VAProfileH264Main, VAEntrypointEncSliceLP, &attributeList);
1387         DDI_CHK_RET(status, "Failed to initialize Caps!");
1388 
1389         VAProfile profile[3] = {
1390             VAProfileH264Main,
1391             VAProfileH264High,
1392             VAProfileH264ConstrainedBaseline};
1393 
1394         for (int32_t i = 0; i < 3; i++)
1395         {
1396             uint32_t configStartIdx = m_encConfigs.size();
1397             AddEncConfig(VA_RC_CQP);
1398 
1399             if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEnableMediaKernels))
1400             {
1401                 /* m_encRcMode[0] is VA_RC_CQP and it is already added */
1402                 for (int32_t j = 1; j < 5; j++)
1403                 {
1404                     AddEncConfig(m_encRcMode[j]);
1405                 }
1406                 AddEncConfig(VA_RC_QVBR);
1407 #if VA_CHECK_VERSION(1, 10, 0)
1408                 AddEncConfig(VA_RC_TCBRC);
1409 #endif
1410             }
1411             AddProfileEntry(profile[i], VAEntrypointEncSliceLP, attributeList,
1412                     configStartIdx, m_encConfigs.size() - configStartIdx);
1413         }
1414     }
1415 #endif
1416 
1417     return status;
1418 }
1419 
LoadMpeg2DecProfileEntrypoints()1420 VAStatus MediaLibvaCaps::LoadMpeg2DecProfileEntrypoints()
1421 {
1422     VAStatus status = VA_STATUS_SUCCESS;
1423 
1424 #ifdef _MPEG2_DECODE_SUPPORTED
1425     AttribMap *attributeList = nullptr;
1426     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrMPEG2VLDDecoding))
1427     {
1428         status = CreateDecAttributes(VAProfileMPEG2Simple, VAEntrypointVLD, &attributeList);
1429         DDI_CHK_RET(status, "Failed to initialize Caps!");
1430 
1431         VAProfile profile[2] = {VAProfileMPEG2Simple, VAProfileMPEG2Main};
1432 
1433         for (int32_t i = 0; i < 2; i++)
1434         {
1435             uint32_t configStartIdx = m_decConfigs.size();
1436             AddDecConfig(VA_DEC_SLICE_MODE_NORMAL, VA_ENCRYPTION_TYPE_NONE, VA_DEC_PROCESSING_NONE);
1437             AddProfileEntry(profile[i], VAEntrypointVLD, attributeList, configStartIdx, 1);
1438         }
1439     }
1440 #endif
1441 
1442     return status;
1443 }
1444 
LoadMpeg2EncProfileEntrypoints()1445 VAStatus MediaLibvaCaps::LoadMpeg2EncProfileEntrypoints()
1446 {
1447     VAStatus status = VA_STATUS_SUCCESS;
1448 
1449 #ifdef _MPEG2_ENCODE_VME_SUPPORTED
1450     AttribMap *attributeList = nullptr;
1451     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEncodeMPEG2))
1452     {
1453         status = CreateEncAttributes(VAProfileMPEG2Simple, VAEntrypointEncSlice, &attributeList);
1454         DDI_CHK_RET(status, "Failed to initialize Caps!");
1455 
1456         VAProfile profile[2] = {VAProfileMPEG2Simple, VAProfileMPEG2Main};
1457         for (int32_t i = 0; i < 2; i++)
1458         {
1459             uint32_t configStartIdx = m_encConfigs.size();
1460             for (int32_t j = 0; j < 3; j++)
1461             {
1462                 AddEncConfig(m_encRcMode[j]);
1463             }
1464             AddProfileEntry(profile[i], VAEntrypointEncSlice, attributeList,
1465                     configStartIdx, m_encConfigs.size() - configStartIdx);
1466         }
1467     }
1468 #endif
1469     return status;
1470 }
1471 
LoadJpegDecProfileEntrypoints()1472 VAStatus MediaLibvaCaps::LoadJpegDecProfileEntrypoints()
1473 {
1474     VAStatus status = VA_STATUS_SUCCESS;
1475 
1476 #ifdef _JPEG_DECODE_SUPPORTED
1477     AttribMap *attributeList = nullptr;
1478     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelJPEGDecoding))
1479     {
1480         status = CreateDecAttributes(VAProfileJPEGBaseline, VAEntrypointVLD, &attributeList);
1481         DDI_CHK_RET(status, "Failed to initialize Caps!");
1482 
1483         uint32_t configStartIdx = m_decConfigs.size();
1484         AddDecConfig(VA_DEC_SLICE_MODE_NORMAL, VA_ENCRYPTION_TYPE_NONE, VA_DEC_PROCESSING_NONE);
1485         AddProfileEntry(VAProfileJPEGBaseline, VAEntrypointVLD, attributeList, configStartIdx, 1);
1486     }
1487 #endif
1488 
1489     return status;
1490 }
1491 
LoadJpegEncProfileEntrypoints()1492 VAStatus MediaLibvaCaps::LoadJpegEncProfileEntrypoints()
1493 {
1494     VAStatus status = VA_STATUS_SUCCESS;
1495 
1496 #ifdef _JPEG_ENCODE_SUPPORTED
1497     AttribMap *attributeList = nullptr;
1498     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEncodeJPEG))
1499     {
1500         status = CreateEncAttributes(VAProfileJPEGBaseline, VAEntrypointEncPicture, &attributeList);
1501         DDI_CHK_RET(status, "Failed to initialize Caps!");
1502         uint32_t configStartIdx = m_encConfigs.size();
1503         AddEncConfig(VA_RC_NONE);
1504         AddProfileEntry(VAProfileJPEGBaseline, VAEntrypointEncPicture, attributeList,
1505                 configStartIdx, 1);
1506     }
1507 #endif
1508     return status;
1509 }
1510 
LoadVc1DecProfileEntrypoints()1511 VAStatus MediaLibvaCaps::LoadVc1DecProfileEntrypoints()
1512 {
1513     VAStatus status = VA_STATUS_SUCCESS;
1514 
1515 #ifdef _VC1_DECODE_SUPPORTED
1516     AttribMap *attributeList = nullptr;
1517     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrVC1VLDDecoding))
1518     {
1519         status = CreateDecAttributes(VAProfileVC1Main, VAEntrypointVLD, &attributeList);
1520         DDI_CHK_RET(status, "Failed to initialize Caps!");
1521         VAProfile profile[3] = {VAProfileVC1Advanced, VAProfileVC1Main, VAProfileVC1Simple};
1522 
1523         for (int32_t i = 0; i < 3; i++)
1524         {
1525             uint32_t configStartIdx = m_decConfigs.size();
1526             AddDecConfig(VA_DEC_SLICE_MODE_NORMAL, VA_ENCRYPTION_TYPE_NONE, VA_DEC_PROCESSING_NONE);
1527             AddProfileEntry(profile[i], VAEntrypointVLD, attributeList, configStartIdx, 1);
1528         }
1529     }
1530 #endif
1531 
1532     return status;
1533 }
1534 
LoadVp8DecProfileEntrypoints()1535 VAStatus MediaLibvaCaps::LoadVp8DecProfileEntrypoints()
1536 {
1537     VAStatus status = VA_STATUS_SUCCESS;
1538 
1539 #ifdef _VP8_DECODE_SUPPORTED
1540     AttribMap *attributeList;
1541     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP8VLDDecoding))
1542     {
1543         status = CreateDecAttributes(VAProfileVP8Version0_3, VAEntrypointVLD, &attributeList);
1544         DDI_CHK_RET(status, "Failed to initialize Caps!");
1545 
1546         uint32_t configStartIdx = m_decConfigs.size();
1547         AddDecConfig(VA_DEC_SLICE_MODE_NORMAL, VA_ENCRYPTION_TYPE_NONE, VA_DEC_PROCESSING_NONE);
1548         AddProfileEntry(VAProfileVP8Version0_3, VAEntrypointVLD, attributeList, configStartIdx, 1);
1549     }
1550 #endif
1551 
1552     return status;
1553 }
1554 
LoadVp8EncProfileEntrypoints()1555 VAStatus MediaLibvaCaps::LoadVp8EncProfileEntrypoints()
1556 {
1557     VAStatus status = VA_STATUS_SUCCESS;
1558 
1559 #ifdef _VP8_ENCODE_SUPPORTED
1560     AttribMap *attributeList;
1561     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEncodeVP8))
1562     {
1563         status = CreateEncAttributes(VAProfileVP8Version0_3, VAEntrypointEncSlice, &attributeList);
1564         DDI_CHK_RET(status, "Failed to initialize Caps!");
1565 
1566         uint32_t configStartIdx = m_encConfigs.size();
1567         for (int32_t j = 0; j < 3; j++)
1568         {
1569             AddEncConfig(m_encRcMode[j]);
1570         }
1571         AddProfileEntry(VAProfileVP8Version0_3, VAEntrypointEncSlice, attributeList,
1572                 configStartIdx, m_encConfigs.size() - configStartIdx);
1573     }
1574 #endif
1575     return status;
1576 }
1577 
LoadAdvancedDecProfileEntrypoints()1578 VAStatus MediaLibvaCaps::LoadAdvancedDecProfileEntrypoints()
1579 {
1580     VAStatus status = VA_STATUS_SUCCESS;
1581 
1582     return status;
1583 }
1584 
LoadVp9DecProfileEntrypoints()1585 VAStatus MediaLibvaCaps::LoadVp9DecProfileEntrypoints()
1586 {
1587     VAStatus status = VA_STATUS_SUCCESS;
1588 
1589 #ifdef _VP9_DECODE_SUPPORTED
1590     AttribMap *attributeList;
1591     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile0Decoding8bit420))
1592     {
1593         status = CreateDecAttributes(VAProfileVP9Profile0, VAEntrypointVLD, &attributeList);
1594         DDI_CHK_RET(status, "Failed to initialize Caps!");
1595 
1596         uint32_t configStartIdx = m_decConfigs.size();
1597         for (int32_t i = 0; i < 2; i++)
1598         {
1599             for (int32_t k = 0; k < 2; k++)
1600             {
1601                 AddDecConfig(m_decSliceMode[i], VA_ENCRYPTION_TYPE_NONE, m_decProcessMode[k]);
1602                 if (m_isEntryptSupported)
1603                 {
1604                     uint32_t encrytTypes[DDI_CP_ENCRYPT_TYPES_NUM];
1605 
1606                     int32_t numTypes = m_CapsCp->GetEncryptionTypes(VAProfileVP9Profile0,
1607                             encrytTypes, DDI_CP_ENCRYPT_TYPES_NUM);
1608 
1609                     if (numTypes > 0)
1610                     {
1611                         for (int32_t l = 0; l < numTypes; l++)
1612                         {
1613                             AddDecConfig(VA_DEC_SLICE_MODE_NORMAL, encrytTypes[l],
1614                                     m_decProcessMode[k]);
1615                         }
1616                     }
1617                 }
1618             }
1619         }
1620 
1621         AddProfileEntry(VAProfileVP9Profile0, VAEntrypointVLD, attributeList,
1622                 configStartIdx, m_decConfigs.size() - configStartIdx);
1623     }
1624 
1625     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrVP9VLD10bProfile2Decoding)
1626             || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile2Decoding12bit420))
1627         {
1628             status = CreateDecAttributes(VAProfileVP9Profile2, VAEntrypointVLD, &attributeList);
1629             DDI_CHK_RET(status, "Failed to initialize Caps!");
1630 
1631             uint32_t configStartIdx = m_decConfigs.size();
1632             for (int32_t i = 0; i < 2; i++)
1633             {
1634                 for (int32_t k = 0; k < 2; k++)
1635                 {
1636                     AddDecConfig(m_decSliceMode[i], VA_ENCRYPTION_TYPE_NONE, m_decProcessMode[k]);
1637                     if (m_isEntryptSupported)
1638                     {
1639 
1640                         uint32_t encrytTypes[DDI_CP_ENCRYPT_TYPES_NUM];
1641 
1642                         int32_t numTypes = m_CapsCp->GetEncryptionTypes(VAProfileVP9Profile2,
1643                                 encrytTypes, DDI_CP_ENCRYPT_TYPES_NUM);
1644 
1645                         if (numTypes > 0)
1646                         {
1647                             for (int32_t l = 0; l < numTypes; l++)
1648                             {
1649                                 AddDecConfig(VA_DEC_SLICE_MODE_NORMAL, encrytTypes[l],
1650                                         m_decProcessMode[k]);
1651                             }
1652                         }
1653                     }
1654                 }
1655             }
1656             AddProfileEntry(VAProfileVP9Profile2, VAEntrypointVLD, attributeList,
1657                     configStartIdx, m_decConfigs.size() - configStartIdx);
1658         }
1659 
1660         if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile1Decoding8bit444))
1661         {
1662             status = CreateDecAttributes(VAProfileVP9Profile1, VAEntrypointVLD, &attributeList);
1663             DDI_CHK_RET(status, "Failed to initialize Caps!");
1664 
1665             uint32_t configStartIdx = m_decConfigs.size();
1666             for (int32_t i = 0; i < 2; i++)
1667             {
1668                 for (int32_t k = 0; k < 2; k++)
1669                 {
1670                     AddDecConfig(m_decSliceMode[i], VA_ENCRYPTION_TYPE_NONE, m_decProcessMode[k]);
1671                     if (m_isEntryptSupported)
1672                     {
1673                         uint32_t encrytTypes[DDI_CP_ENCRYPT_TYPES_NUM];
1674 
1675                         int32_t numTypes = m_CapsCp->GetEncryptionTypes(VAProfileVP9Profile1,
1676                                 encrytTypes, DDI_CP_ENCRYPT_TYPES_NUM);
1677 
1678                         if (numTypes > 0)
1679                         {
1680                             for (int32_t l = 0; l < numTypes; l++)
1681                             {
1682                                 AddDecConfig(VA_DEC_SLICE_MODE_NORMAL, encrytTypes[l],
1683                                         m_decProcessMode[k]);
1684                             }
1685                         }
1686                     }
1687                 }
1688             }
1689             AddProfileEntry(VAProfileVP9Profile1, VAEntrypointVLD, attributeList,
1690                     configStartIdx, m_decConfigs.size() - configStartIdx);
1691         }
1692 
1693         if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile3Decoding10bit444)
1694                 || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelVP9VLDProfile3Decoding12bit444))
1695         {
1696             status = CreateDecAttributes(VAProfileVP9Profile3, VAEntrypointVLD, &attributeList);
1697             DDI_CHK_RET(status, "Failed to initialize Caps!");
1698 
1699             uint32_t configStartIdx = m_decConfigs.size();
1700             for (int32_t i = 0; i < 2; i++)
1701             {
1702                 for (int32_t k = 0; k < 2; k++)
1703                 {
1704                     AddDecConfig(m_decSliceMode[i], VA_ENCRYPTION_TYPE_NONE, m_decProcessMode[k]);
1705                     if (m_isEntryptSupported)
1706                     {
1707                         uint32_t encrytTypes[DDI_CP_ENCRYPT_TYPES_NUM];
1708 
1709                         int32_t numTypes = m_CapsCp->GetEncryptionTypes(VAProfileVP9Profile3,
1710                                 encrytTypes, DDI_CP_ENCRYPT_TYPES_NUM);
1711 
1712                         if (numTypes > 0)
1713                         {
1714                             for (int32_t l = 0; l < numTypes; l++)
1715                             {
1716                                 AddDecConfig(VA_DEC_SLICE_MODE_NORMAL, encrytTypes[l],
1717                                         m_decProcessMode[k]);
1718                             }
1719                         }
1720                     }
1721                 }
1722             }
1723             AddProfileEntry(VAProfileVP9Profile3, VAEntrypointVLD, attributeList,
1724                     configStartIdx, m_decConfigs.size() - configStartIdx);
1725         }
1726 #endif
1727     return status;
1728 }
1729 
LoadVp9EncProfileEntrypoints()1730 VAStatus MediaLibvaCaps::LoadVp9EncProfileEntrypoints()
1731 {
1732     VAStatus status = VA_STATUS_SUCCESS;
1733 
1734     return status;
1735 }
1736 
LoadHevcDecProfileEntrypoints()1737 VAStatus MediaLibvaCaps::LoadHevcDecProfileEntrypoints()
1738 {
1739     VAStatus status = VA_STATUS_SUCCESS;
1740 
1741 #ifdef _HEVC_DECODE_SUPPORTED
1742     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLDMainDecoding)
1743             || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrHEVCVLDMainShortDecoding))
1744     {
1745         LoadDecProfileEntrypoints(VAProfileHEVCMain);
1746     }
1747 
1748     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLDMain10Decoding)
1749             || MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrHEVCVLDMain10ShortDecoding))
1750     {
1751         LoadDecProfileEntrypoints(VAProfileHEVCMain10);
1752     }
1753 
1754     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLDMain12bit420Decoding))
1755     {
1756         LoadDecProfileEntrypoints(VAProfileHEVCMain12);
1757     }
1758 
1759     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLD42210bitDecoding))
1760     {
1761         LoadDecProfileEntrypoints(VAProfileHEVCMain422_10);
1762     }
1763 
1764     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLDMain12bit422Decoding))
1765     {
1766         LoadDecProfileEntrypoints(VAProfileHEVCMain422_12);
1767     }
1768 
1769     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLD4448bitDecoding))
1770     {
1771         LoadDecProfileEntrypoints(VAProfileHEVCMain444);
1772     }
1773 
1774     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLD44410bitDecoding))
1775     {
1776         LoadDecProfileEntrypoints(VAProfileHEVCMain444_10);
1777     }
1778 
1779     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrIntelHEVCVLDMain12bit444Decoding))
1780     {
1781         LoadDecProfileEntrypoints(VAProfileHEVCMain444_12);
1782     }
1783 
1784 #endif
1785     return status;
1786 }
1787 
LoadDecProfileEntrypoints(VAProfile profile)1788 VAStatus MediaLibvaCaps::LoadDecProfileEntrypoints(VAProfile profile)
1789 {
1790     AttribMap *attributeList = nullptr;
1791     VAStatus status = CreateDecAttributes(profile, VAEntrypointVLD, &attributeList);
1792     DDI_CHK_RET(status, "Failed to initialize Caps!");
1793 
1794     uint32_t configStartIdx = m_decConfigs.size();
1795     for (int32_t j = 0; j < 2; j++)
1796     {
1797         for (int32_t k = 0; k < 2; k++)
1798         {
1799             AddDecConfig(m_decSliceMode[j], VA_ENCRYPTION_TYPE_NONE, m_decProcessMode[k]);
1800             if (m_isEntryptSupported)
1801             {
1802                 uint32_t encrytTypes[DDI_CP_ENCRYPT_TYPES_NUM];
1803 
1804                 int32_t numTypes = m_CapsCp->GetEncryptionTypes(profile,
1805                         encrytTypes, DDI_CP_ENCRYPT_TYPES_NUM);
1806 
1807                 if (numTypes > 0)
1808                 {
1809                     for (int32_t l = 0; l < numTypes; l++)
1810                     {
1811                         AddDecConfig(m_decSliceMode[j], encrytTypes[l],
1812                                 m_decProcessMode[k]);
1813                     }
1814                 }
1815             }
1816         }
1817     }
1818     AddProfileEntry(profile, VAEntrypointVLD, attributeList,
1819                 configStartIdx, m_decConfigs.size() - configStartIdx);
1820     return status;
1821 }
1822 
LoadHevcEncProfileEntrypoints()1823 VAStatus MediaLibvaCaps::LoadHevcEncProfileEntrypoints()
1824 {
1825     VAStatus status = VA_STATUS_SUCCESS;
1826     const uint8_t rcModeSize = (sizeof(m_encRcMode))/(sizeof(m_encRcMode[0]));
1827 
1828 #if defined (_HEVC_ENCODE_VME_SUPPORTED) || defined (_HEVC_ENCODE_VDENC_SUPPORTED)
1829     AttribMap *attributeList = nullptr;
1830 
1831     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEncodeHEVC))
1832     {
1833         status = CreateEncAttributes(VAProfileHEVCMain, VAEntrypointEncSlice, &attributeList);
1834         DDI_CHK_RET(status, "Failed to initialize Caps!");
1835         DDI_CHK_NULL(attributeList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
1836 
1837         uint32_t configStartIdx = m_encConfigs.size();
1838 
1839         for (int32_t j = 0; j < rcModeSize; j++)
1840         {
1841             AddEncConfig(m_encRcMode[j]);
1842             AddEncConfig(m_encRcMode[j] | VA_RC_PARALLEL);
1843         }
1844 
1845         AddProfileEntry(VAProfileHEVCMain, VAEntrypointEncSlice, attributeList,
1846                 configStartIdx, m_encConfigs.size() - configStartIdx);
1847 
1848         status = CreateEncAttributes(VAProfileHEVCMain, VAEntrypointFEI, &attributeList);
1849         DDI_CHK_RET(status, "Failed to initialize Caps!");
1850         DDI_CHK_NULL(attributeList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
1851 
1852         configStartIdx = m_encConfigs.size();
1853         AddEncConfig(VA_RC_CQP, VA_FEI_FUNCTION_ENC_PAK);
1854 
1855         AddProfileEntry(VAProfileHEVCMain, VAEntrypointFEI, attributeList,
1856                 configStartIdx, m_encConfigs.size() - configStartIdx);
1857     }
1858 
1859     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEncodeHEVC10bit))
1860     {
1861         status = CreateEncAttributes(VAProfileHEVCMain10, VAEntrypointEncSlice, &attributeList);
1862         DDI_CHK_RET(status, "Failed to initialize Caps!");
1863         DDI_CHK_NULL(attributeList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
1864 
1865         uint32_t configStartIdx = m_encConfigs.size();
1866 
1867         for (int32_t j = 0; j < rcModeSize; j++)
1868         {
1869             AddEncConfig(m_encRcMode[j]);
1870             AddEncConfig(m_encRcMode[j] | VA_RC_PARALLEL);
1871         }
1872 
1873         AddProfileEntry(VAProfileHEVCMain10, VAEntrypointEncSlice, attributeList,
1874                 configStartIdx, m_encConfigs.size() - configStartIdx);
1875     }
1876 
1877     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEncodeHEVC12bit))
1878     {
1879         status = CreateEncAttributes(VAProfileHEVCMain12, VAEntrypointEncSlice, &attributeList);
1880         DDI_CHK_RET(status, "Failed to initialize Caps!");
1881         DDI_CHK_NULL(attributeList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
1882 
1883         uint32_t configStartIdx = m_encConfigs.size();
1884 
1885         for (int32_t j = 0; j < rcModeSize; j++)
1886         {
1887             AddEncConfig(m_encRcMode[j]);
1888             AddEncConfig(m_encRcMode[j] | VA_RC_PARALLEL);
1889         }
1890 
1891         AddProfileEntry(VAProfileHEVCMain12, VAEntrypointEncSlice, attributeList,
1892                 configStartIdx, m_encConfigs.size() - configStartIdx);
1893     }
1894 
1895     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEncodeHEVC10bit422))
1896     {
1897         status = CreateEncAttributes(VAProfileHEVCMain422_10, VAEntrypointEncSlice, &attributeList);
1898         DDI_CHK_RET(status, "Failed to initialize Caps!");
1899         DDI_CHK_NULL(attributeList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
1900 
1901         uint32_t configStartIdx = m_encConfigs.size();
1902 
1903         for (int32_t j = 0; j < rcModeSize; j++)
1904         {
1905             AddEncConfig(m_encRcMode[j]);
1906             AddEncConfig(m_encRcMode[j] | VA_RC_PARALLEL);
1907         }
1908 
1909         AddProfileEntry(VAProfileHEVCMain422_10, VAEntrypointEncSlice, attributeList,
1910                 configStartIdx, m_encConfigs.size() - configStartIdx);
1911     }
1912 
1913     if (MEDIA_IS_SKU(&(m_mediaCtx->SkuTable), FtrEncodeHEVC12bit422))
1914     {
1915         status = CreateEncAttributes(VAProfileHEVCMain422_12, VAEntrypointEncSlice, &attributeList);
1916         DDI_CHK_RET(status, "Failed to initialize Caps!");
1917         DDI_CHK_NULL(attributeList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
1918 
1919         uint32_t configStartIdx = m_encConfigs.size();
1920 
1921         for (int32_t j = 0; j < rcModeSize; j++)
1922         {
1923             AddEncConfig(m_encRcMode[j]);
1924             AddEncConfig(m_encRcMode[j] | VA_RC_PARALLEL);
1925         }
1926 
1927         AddProfileEntry(VAProfileHEVCMain422_12, VAEntrypointEncSlice, attributeList,
1928                 configStartIdx, m_encConfigs.size() - configStartIdx);
1929     }
1930 
1931 #endif
1932     return status;
1933 }
1934 
LoadNoneProfileEntrypoints()1935 VAStatus MediaLibvaCaps::LoadNoneProfileEntrypoints()
1936 {
1937     VAStatus status = VA_STATUS_SUCCESS;
1938 
1939     AttribMap *attributeList = nullptr;
1940 
1941     status = CreateVpAttributes(VAProfileNone, VAEntrypointVideoProc, &attributeList);
1942     DDI_CHK_RET(status, "Failed to initialize Caps!");
1943 
1944     uint32_t configStartIdx = m_vpConfigs.size();
1945     AddVpConfig(0);
1946     AddProfileEntry(VAProfileNone, VAEntrypointVideoProc, attributeList, configStartIdx, 1);
1947 
1948     configStartIdx = m_encConfigs.size();
1949     AddEncConfig(VA_RC_NONE);
1950     AddProfileEntry(VAProfileNone, VAEntrypointStats, attributeList,
1951             configStartIdx, 1);
1952     return status;
1953 }
1954 
GetConfigAttributes(VAProfile profile,VAEntrypoint entrypoint,VAConfigAttrib * attribList,int32_t numAttribs)1955 VAStatus MediaLibvaCaps::GetConfigAttributes(VAProfile profile,
1956         VAEntrypoint entrypoint,
1957         VAConfigAttrib *attribList,
1958         int32_t numAttribs)
1959 {
1960     DDI_CHK_NULL(attribList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
1961     int32_t i = GetProfileTableIdx(profile, entrypoint);
1962 
1963     switch(i)
1964     {
1965         case -2:
1966             return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
1967         case -1:
1968             return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1969         default:
1970             break;
1971     }
1972 
1973     DDI_CHK_NULL(m_profileEntryTbl[i].m_attributes, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
1974     for (int32_t j = 0; j < numAttribs; j++)
1975     {
1976         if (m_profileEntryTbl[i].m_attributes->find(attribList[j].type) !=
1977                 m_profileEntryTbl[i].m_attributes->end())
1978         {
1979             attribList[j].value = (*m_profileEntryTbl[i].m_attributes)[attribList[j].type];
1980         }
1981         else
1982         {
1983             if (GetGeneralConfigAttrib(&attribList[j]) != VA_STATUS_SUCCESS)
1984             {
1985                 //For unknown attribute, set to VA_ATTRIB_NOT_SUPPORTED
1986                 attribList[j].value = VA_ATTRIB_NOT_SUPPORTED;
1987             }
1988         }
1989     }
1990 
1991     return VA_STATUS_SUCCESS;
1992 }
1993 
CreateDecConfig(int32_t profileTableIdx,VAConfigAttrib * attribList,int32_t numAttribs,VAConfigID * configId)1994 VAStatus MediaLibvaCaps::CreateDecConfig(
1995         int32_t profileTableIdx,
1996         VAConfigAttrib *attribList,
1997         int32_t numAttribs,
1998         VAConfigID *configId)
1999 {
2000     DDI_CHK_NULL(configId, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2001 
2002     if (numAttribs)
2003     {
2004         DDI_CHK_NULL(attribList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2005     }
2006 
2007     VAConfigAttrib decAttributes[3];
2008 
2009     decAttributes[0].type = VAConfigAttribDecSliceMode;
2010     decAttributes[0].value = VA_DEC_SLICE_MODE_NORMAL;
2011     decAttributes[1].type = VAConfigAttribEncryption;
2012     decAttributes[1].value = VA_ENCRYPTION_TYPE_NONE;
2013     decAttributes[2].type = VAConfigAttribDecProcessing;
2014     decAttributes[2].value = VA_DEC_PROCESSING_NONE;
2015 
2016     int32_t i,j;
2017     for (j = 0; j < numAttribs; j++)
2018     {
2019         for (i = 0; i < 3; i++)
2020         {
2021             if (attribList[j].type == decAttributes[i].type)
2022             {
2023                 decAttributes[i].value = attribList[j].value;
2024                 break;
2025             }
2026         }
2027     }
2028 
2029     int32_t startIdx = m_profileEntryTbl[profileTableIdx].m_configStartIdx;
2030     int32_t configNum = m_profileEntryTbl[profileTableIdx].m_configNum;
2031     for (i = startIdx; i < (startIdx + configNum); i++)
2032     {
2033         if (decAttributes[0].value == m_decConfigs[i].m_sliceMode
2034                 && decAttributes[1].value == m_decConfigs[i].m_encryptType
2035                 && decAttributes[2].value == m_decConfigs[i].m_processType)
2036         {
2037             break;
2038         }
2039     }
2040 
2041     if (i < (startIdx + configNum))
2042     {
2043         *configId = DDI_CODEC_GEN_CONFIG_ATTRIBUTES_DEC_BASE + i;
2044         return VA_STATUS_SUCCESS;
2045 
2046     }
2047     else
2048     {
2049         *configId = 0xFFFFFFFF;
2050         return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
2051     }
2052 }
2053 
CreateEncConfig(int32_t profileTableIdx,VAEntrypoint entrypoint,VAConfigAttrib * attribList,int32_t numAttribs,VAConfigID * configId)2054 VAStatus MediaLibvaCaps::CreateEncConfig(
2055         int32_t profileTableIdx,
2056         VAEntrypoint entrypoint,
2057         VAConfigAttrib *attribList,
2058         int32_t numAttribs,
2059         VAConfigID *configId)
2060 {
2061     DDI_CHK_NULL(configId, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2062 
2063     if (numAttribs)
2064     {
2065         DDI_CHK_NULL(attribList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2066     }
2067 
2068     uint32_t rcMode = VA_RC_CQP;
2069     if((entrypoint == VAEntrypointStats) || (entrypoint == VAEntrypointEncPicture))
2070     {
2071         rcMode = VA_RC_NONE;
2072     }
2073 
2074     bool rc_mb_flag = false;
2075     if (entrypoint == VAEntrypointEncSliceLP)
2076     {
2077         switch(m_profileEntryTbl[profileTableIdx].m_profile)
2078         {
2079             case VAProfileHEVCMain:
2080             case VAProfileHEVCMain10:
2081             case VAProfileHEVCMain444:
2082             case VAProfileHEVCMain444_10:
2083                 rc_mb_flag = true;
2084                 break;
2085             default:
2086                 rc_mb_flag = false;
2087                 break;
2088         }
2089         m_vdencActive = true;
2090     }
2091 
2092     uint32_t feiFunction = 0;
2093 
2094     int32_t j;
2095     for (j = 0; j < numAttribs; j++)
2096     {
2097         if (VAConfigAttribRateControl == attribList[j].type)
2098         {
2099             //do not set VA_RC_MB without other BRC mode
2100             //if it happend, just set it to default RC mode
2101             if(attribList[j].value != VA_RC_MB)
2102             {
2103                 if ((attribList[j].value == VA_RC_CBR ||
2104                     attribList[j].value == VA_RC_VBR) && rc_mb_flag)
2105                     rcMode = attribList[j].value | VA_RC_MB;
2106                 else
2107                     rcMode = attribList[j].value;
2108             }
2109         }
2110         if(VAConfigAttribFEIFunctionType == attribList[j].type)
2111         {
2112             feiFunction = attribList[j].value;
2113         }
2114         if(VAConfigAttribRTFormat == attribList[j].type)
2115         {
2116             VAConfigAttrib attribRT;
2117             CheckEncRTFormat(m_profileEntryTbl[profileTableIdx].m_profile, entrypoint, &attribRT);
2118             if((attribList[j].value | attribRT.value) == 0)
2119             {
2120                 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
2121             }
2122         }
2123     }
2124 
2125     // If VAEntrypointFEI but FEI type (ENC/PAK/ENCPAK) wasn't provided via VAConfigAttribFEIFunctionType
2126     // then use ENC_PAK as default
2127     if (VAEntrypointFEI == entrypoint && 0 == feiFunction)
2128         feiFunction = VA_FEI_FUNCTION_ENC_PAK;
2129 
2130     int32_t startIdx = m_profileEntryTbl[profileTableIdx].m_configStartIdx;
2131     int32_t configNum = m_profileEntryTbl[profileTableIdx].m_configNum;
2132     for (j = startIdx; j < (startIdx + configNum); j++)
2133     {
2134         if (m_encConfigs[j].m_rcMode == rcMode &&
2135             m_encConfigs[j].m_FeiFunction == feiFunction)
2136         {
2137             break;
2138         }
2139     }
2140 
2141     if (j < (configNum + startIdx))
2142     {
2143         *configId = j + DDI_CODEC_GEN_CONFIG_ATTRIBUTES_ENC_BASE;
2144         return VA_STATUS_SUCCESS;
2145     }
2146     else
2147     {
2148         *configId = 0xFFFFFFFF;
2149         return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
2150     }
2151 }
2152 
CreateVpConfig(int32_t profileTableIdx,VAConfigAttrib * attribList,int32_t numAttribs,VAConfigID * configId)2153 VAStatus MediaLibvaCaps::CreateVpConfig(
2154         int32_t profileTableIdx,
2155         VAConfigAttrib *attribList,
2156         int32_t numAttribs,
2157         VAConfigID *configId)
2158 {
2159     // attribList and numAttribs are for future usage.
2160     DDI_UNUSED(attribList);
2161     DDI_UNUSED(numAttribs);
2162 
2163     DDI_CHK_NULL(configId, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2164 
2165     *configId = m_profileEntryTbl[profileTableIdx].m_configStartIdx
2166         + DDI_VP_GEN_CONFIG_ATTRIBUTES_BASE;
2167 
2168     return VA_STATUS_SUCCESS;
2169 }
2170 
CheckDecodeResolution(int32_t codecMode,VAProfile profile,uint32_t width,uint32_t height)2171 VAStatus MediaLibvaCaps::CheckDecodeResolution(
2172         int32_t codecMode,
2173         VAProfile profile,
2174         uint32_t width,
2175         uint32_t height)
2176 {
2177 
2178     uint32_t maxWidth = 0;
2179     uint32_t maxHeight = 0;
2180     switch (codecMode)
2181     {
2182         case CODECHAL_DECODE_MODE_MPEG2VLD:
2183             maxWidth = m_decMpeg2MaxWidth;
2184             maxHeight = m_decMpeg2MaxHeight;
2185             break;
2186         case CODECHAL_DECODE_MODE_VC1VLD:
2187             maxWidth = m_decVc1MaxWidth;
2188             maxHeight = m_decVc1MaxHeight;
2189             break;
2190         case CODECHAL_DECODE_MODE_JPEG:
2191             maxWidth = m_decJpegMaxWidth;
2192             maxHeight = m_decJpegMaxHeight;
2193             break;
2194         case CODECHAL_DECODE_MODE_HEVCVLD:
2195             maxWidth = m_decHevcMaxWidth;
2196             maxHeight = m_decHevcMaxHeight;
2197             break;
2198         case CODECHAL_DECODE_MODE_VP9VLD:
2199             maxWidth = m_decVp9MaxWidth;
2200             maxHeight = m_decVp9MaxHeight;
2201             break;
2202         default:
2203             maxWidth = m_decDefaultMaxWidth;
2204             maxHeight = m_decDefaultMaxHeight;
2205             break;
2206     }
2207 
2208     uint32_t alignedHeight = 0;
2209     if (profile == VAProfileVC1Advanced)
2210     {
2211         alignedHeight = MOS_ALIGN_CEIL(height,32);
2212     }
2213     else
2214     {
2215         alignedHeight = height;
2216     }
2217 
2218     if (width > maxWidth || alignedHeight > maxHeight)
2219     {
2220         return VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2221     }
2222     else
2223     {
2224         return VA_STATUS_SUCCESS;
2225     }
2226 }
2227 
CheckEncodeResolution(VAProfile profile,uint32_t width,uint32_t height)2228 VAStatus MediaLibvaCaps::CheckEncodeResolution(
2229         VAProfile profile,
2230         uint32_t width,
2231         uint32_t height)
2232 {
2233     switch (profile)
2234     {
2235         case VAProfileJPEGBaseline:
2236             if (width > m_encJpegMaxWidth
2237                     || width < m_encJpegMinWidth
2238                     || height > m_encJpegMaxHeight
2239                     || height <  m_encJpegMinHeight)
2240             {
2241                 return VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2242             }
2243             break;
2244         case VAProfileMPEG2Simple:
2245         case VAProfileMPEG2Main:
2246             if( width > CODEC_MAX_PIC_WIDTH
2247                     || width < m_encMinWidth
2248                     || height > CODEC_MAX_PIC_HEIGHT
2249                     || height < m_encMinHeight)
2250             {
2251                 return VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2252             }
2253             break;
2254         default:
2255             if (width > m_encMax4kWidth
2256                     || width < m_encMinWidth
2257                     || height > m_encMax4kHeight
2258                     || height < m_encMinHeight)
2259             {
2260                 return VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2261             }
2262             break;
2263     }
2264     return VA_STATUS_SUCCESS;
2265 }
2266 
CheckProfile(VAProfile profile)2267 VAStatus MediaLibvaCaps::CheckProfile(VAProfile profile)
2268 {
2269     return VA_STATUS_SUCCESS;
2270 }
2271 
CreateConfig(VAProfile profile,VAEntrypoint entrypoint,VAConfigAttrib * attribList,int32_t numAttribs,VAConfigID * configId)2272 VAStatus MediaLibvaCaps::CreateConfig(
2273         VAProfile profile,
2274         VAEntrypoint entrypoint,
2275         VAConfigAttrib *attribList,
2276         int32_t numAttribs,
2277         VAConfigID *configId)
2278 {
2279 
2280     DDI_CHK_NULL(configId, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2281 
2282     DDI_CHK_RET(CheckProfile(profile),"Failed to check config!");
2283 
2284     int32_t i = GetProfileTableIdx(profile, entrypoint);
2285 
2286     if (i < 0)
2287     {
2288         if(i == -2)
2289         {
2290             return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
2291         }
2292         else
2293         {
2294             return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
2295         }
2296     }
2297 
2298     VAStatus ret = CheckAttribList(profile, entrypoint, attribList, numAttribs);
2299     if(ret != VA_STATUS_SUCCESS)
2300     {
2301         return ret;
2302     }
2303 
2304     if (CheckEntrypointCodecType(entrypoint, videoDecode))
2305     {
2306         return CreateDecConfig(i, attribList, numAttribs, configId);
2307     }
2308     else if(CheckEntrypointCodecType(entrypoint, videoProcess))
2309     {
2310         return CreateVpConfig(i, attribList, numAttribs, configId);
2311     }
2312     else if(CheckEntrypointCodecType(entrypoint, videoEncode))
2313     {
2314         return CreateEncConfig(i,entrypoint,attribList, numAttribs, configId);
2315     }
2316     else if(CheckEntrypointCodecType(entrypoint, videoProtect))
2317     {
2318         return m_CapsCp->CreateCpConfig(i, entrypoint, attribList, numAttribs, configId);
2319     }
2320     else
2321     {
2322         DDI_ASSERTMESSAGE("DDI: Unsupported EntryPoint");
2323         return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
2324     }
2325 }
2326 
QueryConfigProfiles(VAProfile * profileList,int32_t * numProfiles)2327 VAStatus MediaLibvaCaps::QueryConfigProfiles(
2328         VAProfile *profileList,
2329         int32_t *numProfiles)
2330 {
2331     DDI_CHK_NULL(profileList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2332     DDI_CHK_NULL(numProfiles, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2333     std::set<int32_t> profiles;
2334     int32_t i;
2335     for (i = 0; i < m_profileEntryCount; i++)
2336     {
2337         profiles.insert((int32_t)m_profileEntryTbl[i].m_profile);
2338     }
2339 
2340     std::set<int32_t>::iterator it;
2341     for (it = profiles.begin(), i = 0; it != profiles.end(); ++it, i++)
2342     {
2343         profileList[i] = (VAProfile)*it;
2344     }
2345 
2346     *numProfiles = i;
2347 
2348     DDI_CHK_CONDITION((i > DDI_CODEC_GEN_MAX_PROFILES),
2349             "Execeed maximum number of profiles!", VA_STATUS_ERROR_MAX_NUM_EXCEEDED);
2350     return VA_STATUS_SUCCESS;
2351 }
2352 
QueryConfigEntrypoints(VAProfile profile,VAEntrypoint * entrypointList,int32_t * numEntrypoints)2353 VAStatus MediaLibvaCaps::QueryConfigEntrypoints(
2354         VAProfile profile,
2355         VAEntrypoint *entrypointList,
2356         int32_t *numEntrypoints)
2357 {
2358     DDI_CHK_NULL(entrypointList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2359     DDI_CHK_NULL(numEntrypoints, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2360     int32_t j = 0;
2361     for (int32_t i = 0; i < m_profileEntryCount; i++)
2362     {
2363         if (m_profileEntryTbl[i].m_profile == profile)
2364         {
2365             entrypointList[j] = m_profileEntryTbl[i].m_entrypoint;
2366             j++;
2367         }
2368     }
2369     *numEntrypoints = j;
2370     DDI_CHK_CONDITION((j == 0), "cant find the profile!", VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2371     /* If the assert fails then GEN_MAX_ENTRYPOINTS needs to be bigger */
2372     DDI_CHK_CONDITION((j > DDI_CODEC_GEN_MAX_ENTRYPOINTS),
2373             "Execeed maximum number of profiles!", VA_STATUS_ERROR_MAX_NUM_EXCEEDED);
2374 
2375     return VA_STATUS_SUCCESS;
2376 }
2377 
QueryConfigAttributes(VAConfigID configId,VAProfile * profile,VAEntrypoint * entrypoint,VAConfigAttrib * attribList,int32_t * numAttribs)2378 VAStatus MediaLibvaCaps::QueryConfigAttributes(
2379         VAConfigID configId,
2380         VAProfile *profile,
2381         VAEntrypoint *entrypoint,
2382         VAConfigAttrib *attribList,
2383         int32_t *numAttribs)
2384 {
2385     DDI_CHK_NULL(profile, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2386     DDI_CHK_NULL(entrypoint, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2387     DDI_CHK_NULL(attribList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2388     DDI_CHK_NULL(numAttribs, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2389     int32_t profileTableIdx = -1;
2390     VAStatus status = GetProfileEntrypointFromConfigId(configId, profile, entrypoint, &profileTableIdx);
2391     DDI_CHK_RET(status, "Invalide config_id!");
2392     if (profileTableIdx < 0 || profileTableIdx >= m_profileEntryCount)
2393     {
2394         return VA_STATUS_ERROR_INVALID_CONFIG;
2395     }
2396     auto allAttribsList = m_profileEntryTbl[profileTableIdx].m_attributes;
2397 
2398     DDI_CHK_NULL(allAttribsList, "Null pointer", VA_STATUS_ERROR_INVALID_CONFIG);
2399 
2400     uint32_t j = 0;
2401     for (auto it = allAttribsList->begin(); it != allAttribsList->end(); ++it)
2402     {
2403         if (it->second != VA_ATTRIB_NOT_SUPPORTED)
2404         {
2405             attribList[j].type = it->first;
2406             attribList[j].value = it->second;
2407             j++;
2408         }
2409     }
2410 
2411     *numAttribs = j;
2412     // tracing profile/entry/config, compiler will optimize if trace is disabled
2413     uint32_t data[] = {*profile, *entrypoint, j};
2414     MOS_TraceEventExt(EVENT_VA_CONFIG, EVENT_TYPE_INFO, data, sizeof(data), attribList, j*sizeof(VAConfigAttrib));
2415 
2416     return VA_STATUS_SUCCESS;
2417 }
2418 
GetEncConfigAttr(VAConfigID configId,VAProfile * profile,VAEntrypoint * entrypoint,uint32_t * rcMode,uint32_t * feiFunction)2419 VAStatus MediaLibvaCaps::GetEncConfigAttr(
2420         VAConfigID configId,
2421         VAProfile *profile,
2422         VAEntrypoint *entrypoint,
2423         uint32_t *rcMode,
2424         uint32_t *feiFunction)
2425 {
2426     DDI_CHK_NULL(profile, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2427     DDI_CHK_NULL(entrypoint, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2428     DDI_CHK_NULL(rcMode, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2429     int32_t profileTableIdx = -1;
2430     int32_t configOffset = configId - DDI_CODEC_GEN_CONFIG_ATTRIBUTES_ENC_BASE;
2431     VAStatus status = GetProfileEntrypointFromConfigId(configId, profile, entrypoint, &profileTableIdx);
2432     DDI_CHK_RET(status, "Invalide config_id!");
2433     if (profileTableIdx < 0 || profileTableIdx >= m_profileEntryCount)
2434     {
2435         return VA_STATUS_ERROR_INVALID_CONFIG;
2436     }
2437 
2438     int32_t configStart = m_profileEntryTbl[profileTableIdx].m_configStartIdx;
2439     int32_t configEnd = m_profileEntryTbl[ profileTableIdx].m_configStartIdx
2440         + m_profileEntryTbl[profileTableIdx].m_configNum;
2441 
2442     if (configOffset < configStart || configOffset > configEnd)
2443     {
2444         return VA_STATUS_ERROR_INVALID_CONFIG;
2445     }
2446     *rcMode = m_encConfigs[configOffset].m_rcMode;
2447     *feiFunction = m_encConfigs[configOffset].m_FeiFunction;
2448     return VA_STATUS_SUCCESS;
2449 }
2450 
GetDecConfigAttr(VAConfigID configId,VAProfile * profile,VAEntrypoint * entrypoint,uint32_t * sliceMode,uint32_t * encryptType,uint32_t * processMode)2451 VAStatus MediaLibvaCaps::GetDecConfigAttr(
2452         VAConfigID configId,
2453         VAProfile *profile,
2454         VAEntrypoint *entrypoint,
2455         uint32_t *sliceMode,
2456         uint32_t *encryptType,
2457         uint32_t *processMode)
2458 {
2459     DDI_CHK_NULL(profile, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2460     DDI_CHK_NULL(entrypoint, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2461     DDI_CHK_NULL(sliceMode, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2462     DDI_CHK_NULL(encryptType, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2463     DDI_CHK_NULL(processMode, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2464 
2465     int32_t profileTableIdx = -1;
2466     int32_t configOffset = configId - DDI_CODEC_GEN_CONFIG_ATTRIBUTES_DEC_BASE;
2467     VAStatus status = GetProfileEntrypointFromConfigId(configId, profile, entrypoint, &profileTableIdx);
2468     DDI_CHK_RET(status, "Invalide config_id!");
2469     if (profileTableIdx < 0 || profileTableIdx >= m_profileEntryCount)
2470     {
2471         return VA_STATUS_ERROR_INVALID_CONFIG;
2472     }
2473 
2474     int32_t configStart = m_profileEntryTbl[profileTableIdx].m_configStartIdx;
2475     int32_t configEnd = m_profileEntryTbl[ profileTableIdx].m_configStartIdx
2476         + m_profileEntryTbl[profileTableIdx].m_configNum;
2477 
2478     if (configOffset < configStart || configOffset > configEnd)
2479     {
2480         return VA_STATUS_ERROR_INVALID_CONFIG;
2481     }
2482 
2483     if (sliceMode)
2484     {
2485         *sliceMode =  m_decConfigs[configOffset].m_sliceMode;
2486     }
2487 
2488     if (encryptType)
2489     {
2490         *encryptType =  m_decConfigs[configOffset].m_encryptType;
2491     }
2492 
2493     if (processMode)
2494     {
2495         *processMode =  m_decConfigs[configOffset].m_processType;
2496     }
2497     return VA_STATUS_SUCCESS;
2498 }
2499 
GetVpConfigAttr(VAConfigID configId,VAProfile * profile,VAEntrypoint * entrypoint)2500 VAStatus MediaLibvaCaps::GetVpConfigAttr(
2501         VAConfigID configId,
2502         VAProfile *profile,
2503         VAEntrypoint *entrypoint)
2504 {
2505     DDI_CHK_NULL(profile, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2506     DDI_CHK_NULL(entrypoint, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
2507     int32_t profileTableIdx = -1;
2508     int32_t configOffset = configId - DDI_VP_GEN_CONFIG_ATTRIBUTES_BASE;
2509     VAStatus status = GetProfileEntrypointFromConfigId(configId, profile, entrypoint, &profileTableIdx);
2510     DDI_CHK_RET(status, "Invalide config_id!");
2511     if (profileTableIdx < 0 || profileTableIdx >= m_profileEntryCount)
2512     {
2513         return VA_STATUS_ERROR_INVALID_CONFIG;
2514     }
2515 
2516     int32_t configStart = m_profileEntryTbl[profileTableIdx].m_configStartIdx;
2517     int32_t configEnd = m_profileEntryTbl[ profileTableIdx].m_configStartIdx
2518         + m_profileEntryTbl[profileTableIdx].m_configNum;
2519 
2520     if (configOffset < configStart || configOffset > configEnd)
2521     {
2522         return VA_STATUS_ERROR_INVALID_CONFIG;
2523     }
2524 
2525     return VA_STATUS_SUCCESS;
2526 }
2527 
QueryProcessingRate(VAConfigID configId,VAProcessingRateParameter * procBuf,uint32_t * processingRate)2528 VAStatus MediaLibvaCaps::QueryProcessingRate(
2529         VAConfigID configId,
2530         VAProcessingRateParameter *procBuf,
2531         uint32_t *processingRate)
2532 {
2533     DDI_CHK_NULL(procBuf, "Null procBuf",        VA_STATUS_ERROR_INVALID_PARAMETER);
2534     DDI_CHK_NULL(processingRate, "Null processingRate", VA_STATUS_ERROR_INVALID_PARAMETER);
2535 
2536     int32_t profileTableIdx = -1;
2537     VAEntrypoint entrypoint;
2538     VAProfile profile;
2539     VAStatus status = GetProfileEntrypointFromConfigId(configId, &profile, &entrypoint, &profileTableIdx);
2540     DDI_CHK_RET(status, "Invalide config_id!");
2541     if (profileTableIdx < 0 || profileTableIdx >= m_profileEntryCount)
2542     {
2543         return VA_STATUS_ERROR_INVALID_CONFIG;
2544     }
2545 
2546     PLATFORM platform;
2547     MEDIA_FEATURE_TABLE skuTable;
2548     MEDIA_WA_TABLE waTable;
2549     memset(&platform, 0, sizeof(platform));
2550 
2551     if (MOS_STATUS_SUCCESS != HWInfo_GetGfxInfo(m_mediaCtx->fd, m_mediaCtx->pDrmBufMgr, &platform, &skuTable, &waTable, m_mediaCtx->pGtSystemInfo))
2552     {
2553         DDI_ASSERTMESSAGE("Fatal error - Cannot get Sku/Wa Tables/GtSystemInfo and Platform information");
2554         return VA_STATUS_ERROR_OPERATION_FAILED;
2555     }
2556 
2557     const int32_t tuIdxTable[] = {7, 6, 5, 4, 3, 2, 1, 0};
2558     VAProcessingRateParameterEnc *processingRateBuffEnc = nullptr;
2559     VAProcessingRateParameterDec *processingRateBuffDec = nullptr;
2560     uint32_t tuIdx = tuIdxTable[TARGETUSAGE_BEST_SPEED];
2561     VAStatus res = VA_STATUS_SUCCESS;
2562     CODECHAL_MODE encodeMode = CODECHAL_UNSUPPORTED_MODE;
2563 
2564     if ((entrypoint == VAEntrypointEncSlice) ||
2565          (entrypoint == VAEntrypointEncSliceLP))
2566     {
2567         // Get VAProcessingBufferEnc
2568         processingRateBuffEnc = &procBuf->proc_buf_enc;
2569 
2570         if (processingRateBuffEnc &&
2571         processingRateBuffEnc->quality_level < sizeof(tuIdxTable) / sizeof(tuIdxTable[0]))
2572         {
2573             // If app passes the rate input data from DDI and also its TU is valid, then use it
2574             tuIdx = tuIdxTable[processingRateBuffEnc->quality_level];
2575         }
2576 
2577         if (IsAvcProfile(profile))
2578         {
2579             encodeMode = CODECHAL_ENCODE_MODE_AVC;
2580         }
2581         else if(IsMpeg2Profile(profile))
2582         {
2583             encodeMode = CODECHAL_ENCODE_MODE_MPEG2;
2584         }
2585         else if (IsVp8Profile(profile))
2586         {
2587             encodeMode = CODECHAL_ENCODE_MODE_VP8;
2588         }
2589         else if (IsJpegProfile(profile))
2590         {
2591             encodeMode = CODECHAL_ENCODE_MODE_JPEG;
2592         }
2593         else if(IsHevcProfile(profile))
2594         {
2595             encodeMode = CODECHAL_ENCODE_MODE_HEVC;
2596         }
2597         else if (IsVp9Profile(profile))
2598         {
2599             encodeMode = CODECHAL_ENCODE_MODE_VP9;
2600         }
2601 
2602         res = GetMbProcessingRateEnc(
2603                 &skuTable,
2604                 tuIdx,
2605                 encodeMode,
2606                 (entrypoint == VAEntrypointEncSliceLP),
2607                 processingRate);
2608     }
2609     else if (entrypoint == VAEntrypointVLD)
2610     {
2611         // Get VAProcessingBufferEnc
2612         processingRateBuffDec = & procBuf->proc_buf_dec;
2613 
2614         res = GetMbProcessingRateDec(
2615                 &skuTable,
2616                 processingRate);
2617     }
2618     else // VA_PROCESSING_RATE_NONE or else
2619     {
2620         return VA_STATUS_ERROR_INVALID_PARAMETER;
2621     }
2622 
2623     return res;
2624 }
2625 
QuerySurfaceAttributes(VAConfigID configId,VASurfaceAttrib * attribList,uint32_t * numAttribs)2626 VAStatus MediaLibvaCaps::QuerySurfaceAttributes(
2627         VAConfigID configId,
2628         VASurfaceAttrib *attribList,
2629         uint32_t *numAttribs)
2630 {
2631     DDI_CHK_NULL(numAttribs, "Null num_attribs", VA_STATUS_ERROR_INVALID_PARAMETER);
2632 
2633     if (attribList == nullptr)
2634     {
2635         *numAttribs = DDI_CODEC_GEN_MAX_SURFACE_ATTRIBUTES;
2636         return VA_STATUS_SUCCESS;
2637     }
2638 
2639     int32_t profileTableIdx = -1;
2640     VAEntrypoint entrypoint;
2641     VAProfile profile;
2642     VAStatus status = GetProfileEntrypointFromConfigId(configId, &profile, &entrypoint, &profileTableIdx);
2643     DDI_CHK_RET(status, "Invalid config_id!");
2644     if (profileTableIdx < 0 || profileTableIdx >= m_profileEntryCount)
2645     {
2646         return VA_STATUS_ERROR_INVALID_CONFIG;
2647     }
2648 
2649     VASurfaceAttrib *attribs = (VASurfaceAttrib *)MOS_AllocAndZeroMemory(DDI_CODEC_GEN_MAX_SURFACE_ATTRIBUTES * sizeof(*attribs));
2650     if (attribs == nullptr)
2651     {
2652         return VA_STATUS_ERROR_ALLOCATION_FAILED;
2653     }
2654 
2655     uint32_t i = 0;
2656 
2657     if (entrypoint == VAEntrypointVideoProc)   /* vpp */
2658     {
2659         attribs[i].type = VASurfaceAttribPixelFormat;
2660         attribs[i].value.type = VAGenericValueTypeInteger;
2661         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2662         attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
2663         i++;
2664 
2665         attribs[i].type = VASurfaceAttribMaxWidth;
2666         attribs[i].value.type = VAGenericValueTypeInteger;
2667         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2668         attribs[i].value.value.i = VP_MAX_PIC_WIDTH;
2669         i++;
2670 
2671         attribs[i].type = VASurfaceAttribMaxHeight;
2672         attribs[i].value.type = VAGenericValueTypeInteger;
2673         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2674         attribs[i].value.value.i = VP_MAX_PIC_HEIGHT;
2675         i++;
2676 
2677         attribs[i].type = VASurfaceAttribMinWidth;
2678         attribs[i].value.type = VAGenericValueTypeInteger;
2679         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2680         attribs[i].value.value.i = VP_MIN_PIC_WIDTH;
2681         i++;
2682 
2683         attribs[i].type = VASurfaceAttribMinHeight;
2684         attribs[i].value.type = VAGenericValueTypeInteger;
2685         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2686         attribs[i].value.value.i = VP_MIN_PIC_HEIGHT;
2687         i++;
2688 
2689         for (uint32_t j = 0; j < m_numVpSurfaceAttr; j++)
2690         {
2691             attribs[i].type = VASurfaceAttribPixelFormat;
2692             attribs[i].value.type = VAGenericValueTypeInteger;
2693             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2694             attribs[i].value.value.i = m_vpSurfaceAttr[j];
2695             i++;
2696         }
2697 
2698         attribs[i].type = VASurfaceAttribMemoryType;
2699         attribs[i].value.type = VAGenericValueTypeInteger;
2700         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2701         attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
2702             VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR |
2703             VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
2704             VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME |
2705             VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2;
2706         i++;
2707 
2708         attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
2709         attribs[i].value.type = VAGenericValueTypePointer;
2710         attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
2711         attribs[i].value.value.p = nullptr; /* ignore */
2712         i++;
2713     }
2714     else if (entrypoint == VAEntrypointVLD)    /* vld */
2715     {
2716         if (profile == VAProfileHEVCMain10 || profile == VAProfileVP9Profile2)
2717         {
2718             attribs[i].type = VASurfaceAttribPixelFormat;
2719             attribs[i].value.type = VAGenericValueTypeInteger;
2720             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2721             attribs[i].value.value.i = VA_FOURCC_P010;
2722             i++;
2723 
2724             if(profile == VAProfileVP9Profile2)
2725             {
2726                 attribs[i].type = VASurfaceAttribPixelFormat;
2727                 attribs[i].value.type = VAGenericValueTypeInteger;
2728                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2729                 attribs[i].value.value.i = VA_FOURCC_P012;
2730                 i++;
2731 
2732                 attribs[i].type = VASurfaceAttribPixelFormat;
2733                 attribs[i].value.type = VAGenericValueTypeInteger;
2734                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2735                 attribs[i].value.value.i = VA_FOURCC_P016;
2736                 i++;
2737             }
2738         }
2739         else if(profile == VAProfileHEVCMain12)
2740         {
2741             attribs[i].type = VASurfaceAttribPixelFormat;
2742             attribs[i].value.type = VAGenericValueTypeInteger;
2743             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2744             attribs[i].value.value.i = VA_FOURCC_P012;
2745             i++;
2746 
2747             attribs[i].type = VASurfaceAttribPixelFormat;
2748             attribs[i].value.type = VAGenericValueTypeInteger;
2749             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2750             attribs[i].value.value.i = VA_FOURCC_P016;
2751             i++;
2752         }
2753         else if(profile == VAProfileHEVCMain422_10)
2754         {
2755             attribs[i].type = VASurfaceAttribPixelFormat;
2756             attribs[i].value.type = VAGenericValueTypeInteger;
2757             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2758             attribs[i].value.value.i = VA_FOURCC_YUY2;
2759             i++;
2760 
2761             attribs[i].type = VASurfaceAttribPixelFormat;
2762             attribs[i].value.type = VAGenericValueTypeInteger;
2763             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2764             attribs[i].value.value.i = VA_FOURCC_Y210;
2765             i++;
2766         }
2767         else if(profile == VAProfileHEVCMain422_12)
2768         {
2769             //hevc  rext: Y216 12/16bit 422
2770 #if VA_CHECK_VERSION(1, 9, 0)
2771             attribs[i].type = VASurfaceAttribPixelFormat;
2772             attribs[i].value.type = VAGenericValueTypeInteger;
2773             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2774             attribs[i].value.value.i = VA_FOURCC_Y212;
2775             i++;
2776 #endif
2777 
2778             attribs[i].type = VASurfaceAttribPixelFormat;
2779             attribs[i].value.type = VAGenericValueTypeInteger;
2780             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2781             attribs[i].value.value.i = VA_FOURCC_Y216;
2782             i++;
2783 
2784             attribs[i].type = VASurfaceAttribPixelFormat;
2785             attribs[i].value.type = VAGenericValueTypeInteger;
2786             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2787             attribs[i].value.value.i = VA_FOURCC_P012;
2788             i++;
2789         }
2790         else if(profile == VAProfileHEVCMain444 || profile == VAProfileVP9Profile1)
2791         {
2792             attribs[i].type = VASurfaceAttribPixelFormat;
2793             attribs[i].value.type = VAGenericValueTypeInteger;
2794             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2795             attribs[i].value.value.i = VA_FOURCC_AYUV;
2796             i++;
2797 
2798 #if VA_CHECK_VERSION(1, 13, 0)
2799             attribs[i].type = VASurfaceAttribPixelFormat;
2800             attribs[i].value.type = VAGenericValueTypeInteger;
2801             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2802             attribs[i].value.value.i = VA_FOURCC_XYUV;
2803             i++;
2804 #endif
2805         }
2806         else if(profile == VAProfileHEVCMain444_10 || profile == VAProfileVP9Profile3)
2807         {
2808             attribs[i].type = VASurfaceAttribPixelFormat;
2809             attribs[i].value.type = VAGenericValueTypeInteger;
2810             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2811             attribs[i].value.value.i = VA_FOURCC_Y410;
2812             i++;
2813 
2814             if(profile == VAProfileVP9Profile3)
2815             {
2816 #if VA_CHECK_VERSION(1, 9, 0)
2817                 attribs[i].type = VASurfaceAttribPixelFormat;
2818                 attribs[i].value.type = VAGenericValueTypeInteger;
2819                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2820                 attribs[i].value.value.i = VA_FOURCC_Y412;
2821                 i++;
2822 #endif
2823 
2824                 attribs[i].type = VASurfaceAttribPixelFormat;
2825                 attribs[i].value.type = VAGenericValueTypeInteger;
2826                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2827                 attribs[i].value.value.i = VA_FOURCC_Y416;
2828                 i++;
2829             }
2830         }
2831         else if(profile == VAProfileHEVCMain444_12)
2832         {
2833 #if VA_CHECK_VERSION(1, 9, 0)
2834             attribs[i].type = VASurfaceAttribPixelFormat;
2835             attribs[i].value.type = VAGenericValueTypeInteger;
2836             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2837             attribs[i].value.value.i = VA_FOURCC_Y412;
2838             i++;
2839 
2840             attribs[i].type = VASurfaceAttribPixelFormat;
2841             attribs[i].value.type = VAGenericValueTypeInteger;
2842             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2843             attribs[i].value.value.i = VA_FOURCC_Y212;
2844             i++;
2845 #endif
2846 
2847             attribs[i].type = VASurfaceAttribPixelFormat;
2848             attribs[i].value.type = VAGenericValueTypeInteger;
2849             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2850             attribs[i].value.value.i = VA_FOURCC_Y416;
2851             i++;
2852 
2853             attribs[i].type = VASurfaceAttribPixelFormat;
2854             attribs[i].value.type = VAGenericValueTypeInteger;
2855             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2856             attribs[i].value.value.i = VA_FOURCC_P012;
2857             i++;
2858         }
2859         else if (profile == VAProfileJPEGBaseline)
2860         {
2861             for (uint32_t j = 0; j < m_numJpegSurfaceAttr; j++)
2862             {
2863                 attribs[i].type = VASurfaceAttribPixelFormat;
2864                 attribs[i].value.type = VAGenericValueTypeInteger;
2865                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2866                 attribs[i].value.value.i = m_jpegSurfaceAttr[j];
2867                 i++;
2868             }
2869         }
2870         else
2871         {
2872             attribs[i].type = VASurfaceAttribPixelFormat;
2873             attribs[i].value.type = VAGenericValueTypeInteger;
2874             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2875             attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
2876             i++;
2877         }
2878 
2879         auto maxWidth = m_decDefaultMaxWidth;
2880         auto maxHeight = m_decDefaultMaxHeight;
2881         if(IsMpeg2Profile(profile))
2882         {
2883             maxWidth = m_decMpeg2MaxWidth;
2884             maxHeight = m_decMpeg2MaxHeight;
2885         }
2886         else if(IsHevcProfile(profile))
2887         {
2888             maxWidth = m_decHevcMaxWidth;
2889             maxHeight = m_decHevcMaxHeight;
2890         }
2891         else if(IsVc1Profile(profile))
2892         {
2893             maxWidth = m_decVc1MaxWidth;
2894             maxHeight = m_decVc1MaxHeight;
2895         }
2896         else if(IsJpegProfile(profile))
2897         {
2898             maxWidth = m_decJpegMaxWidth;
2899             maxHeight = m_decJpegMaxHeight;
2900         }
2901         else if(IsVp9Profile(profile))
2902         {
2903             maxWidth = m_decVp9MaxWidth;
2904             maxHeight = m_decVp9MaxHeight;
2905         }
2906 
2907         attribs[i].type = VASurfaceAttribMaxWidth;
2908         attribs[i].value.type = VAGenericValueTypeInteger;
2909         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
2910         attribs[i].value.value.i = maxWidth;
2911         i++;
2912 
2913         attribs[i].type = VASurfaceAttribMaxHeight;
2914         attribs[i].value.type = VAGenericValueTypeInteger;
2915         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
2916         attribs[i].value.value.i = maxHeight;
2917         i++;
2918 
2919         attribs[i].type = VASurfaceAttribMemoryType;
2920         attribs[i].value.type = VAGenericValueTypeInteger;
2921         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2922         attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
2923             VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR |
2924             VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
2925             VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME |
2926             VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2;
2927         i++;
2928     }
2929     else if(entrypoint == VAEntrypointEncSlice || entrypoint == VAEntrypointEncSliceLP || entrypoint == VAEntrypointEncPicture || entrypoint == VAEntrypointFEI)
2930     {
2931         if (profile == VAProfileHEVCMain10 || profile == VAProfileVP9Profile2)
2932         {
2933             attribs[i].type = VASurfaceAttribPixelFormat;
2934             attribs[i].value.type = VAGenericValueTypeInteger;
2935             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2936             attribs[i].value.value.i = VA_FOURCC('P', '0', '1', '0');
2937             i++;
2938         }
2939         else if(profile == VAProfileHEVCMain12)
2940         {
2941             attribs[i].type = VASurfaceAttribPixelFormat;
2942             attribs[i].value.type = VAGenericValueTypeInteger;
2943             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2944             attribs[i].value.value.i = VA_FOURCC_P012;
2945             i++;
2946 
2947             attribs[i].type = VASurfaceAttribPixelFormat;
2948             attribs[i].value.type = VAGenericValueTypeInteger;
2949             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2950             attribs[i].value.value.i = VA_FOURCC_P016;
2951             i++;
2952         }
2953         else if(profile == VAProfileHEVCMain422_10)
2954         {
2955             attribs[i].type = VASurfaceAttribPixelFormat;
2956             attribs[i].value.type = VAGenericValueTypeInteger;
2957             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2958             attribs[i].value.value.i = VA_FOURCC_YUY2;
2959             i++;
2960 
2961             attribs[i].type = VASurfaceAttribPixelFormat;
2962             attribs[i].value.type = VAGenericValueTypeInteger;
2963             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2964             attribs[i].value.value.i = VA_FOURCC_Y210;
2965             i++;
2966         }
2967         else if(profile == VAProfileHEVCMain422_12)
2968         {
2969             //hevc  rext: Y216 12/16bit 422
2970 #if VA_CHECK_VERSION(1, 9, 0)
2971             attribs[i].type = VASurfaceAttribPixelFormat;
2972             attribs[i].value.type = VAGenericValueTypeInteger;
2973             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2974             attribs[i].value.value.i = VA_FOURCC_Y212;
2975             i++;
2976 #endif
2977 
2978             attribs[i].type = VASurfaceAttribPixelFormat;
2979             attribs[i].value.type = VAGenericValueTypeInteger;
2980             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2981             attribs[i].value.value.i = VA_FOURCC_Y216;
2982             i++;
2983         }
2984         else if (profile == VAProfileJPEGBaseline)
2985         {
2986             for (uint32_t j = 0; j < m_numJpegEncSurfaceAttr; j++)
2987             {
2988                 attribs[i].type = VASurfaceAttribPixelFormat;
2989                 attribs[i].value.type = VAGenericValueTypeInteger;
2990                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
2991                 attribs[i].value.value.i = m_jpegEncSurfaceAttr[j];
2992                 i++;
2993             }
2994         }
2995         else
2996         {
2997             attribs[i].type = VASurfaceAttribPixelFormat;
2998             attribs[i].value.type = VAGenericValueTypeInteger;
2999             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
3000             attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
3001             i++;
3002         }
3003         attribs[i].type = VASurfaceAttribMaxWidth;
3004         attribs[i].value.type = VAGenericValueTypeInteger;
3005         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
3006         attribs[i].value.value.i = CODEC_MAX_PIC_WIDTH;
3007 
3008         if(profile == VAProfileJPEGBaseline)
3009         {
3010             attribs[i].value.value.i = ENCODE_JPEG_MAX_PIC_WIDTH;
3011         }
3012         if(IsAvcProfile(profile)||IsHevcProfile(profile)||IsVp8Profile(profile))
3013         {
3014             attribs[i].value.value.i = CODEC_4K_MAX_PIC_WIDTH;
3015         }
3016         i++;
3017 
3018         attribs[i].type = VASurfaceAttribMaxHeight;
3019         attribs[i].value.type = VAGenericValueTypeInteger;
3020         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
3021         attribs[i].value.value.i = CODEC_MAX_PIC_HEIGHT;
3022         if(profile == VAProfileJPEGBaseline)
3023         {
3024             attribs[i].value.value.i = ENCODE_JPEG_MAX_PIC_HEIGHT;
3025         }
3026         if(IsAvcProfile(profile)||IsHevcProfile(profile)||IsVp8Profile(profile))
3027         {
3028             attribs[i].value.value.i = CODEC_4K_MAX_PIC_HEIGHT;
3029         }
3030         i++;
3031 
3032         attribs[i].type = VASurfaceAttribMinWidth;
3033         attribs[i].value.type = VAGenericValueTypeInteger;
3034         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
3035         attribs[i].value.value.i = m_encMinWidth;
3036         if(profile == VAProfileJPEGBaseline)
3037         {
3038             attribs[i].value.value.i = m_encJpegMinWidth;
3039         }
3040         i++;
3041 
3042         attribs[i].type = VASurfaceAttribMinHeight;
3043         attribs[i].value.type = VAGenericValueTypeInteger;
3044         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
3045         attribs[i].value.value.i = m_encMinHeight;
3046         if(profile == VAProfileJPEGBaseline)
3047         {
3048             attribs[i].value.value.i = m_encJpegMinHeight;
3049         }
3050         i++;
3051 
3052         attribs[i].type = VASurfaceAttribMemoryType;
3053         attribs[i].value.type = VAGenericValueTypeInteger;
3054         attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
3055         attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
3056             VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR |
3057             VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
3058             VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME |
3059             VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2;
3060         i++;
3061     }
3062     else
3063     {
3064         MOS_FreeMemory(attribs);
3065         return VA_STATUS_ERROR_UNIMPLEMENTED;
3066     }
3067 
3068     if (i > *numAttribs)
3069     {
3070         *numAttribs = i;
3071         MOS_FreeMemory(attribs);
3072         return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
3073     }
3074 
3075     *numAttribs = i;
3076     MOS_SecureMemcpy(attribList, i * sizeof(*attribs), attribs, i * sizeof(*attribs));
3077 
3078     MOS_FreeMemory(attribs);
3079     return status;
3080 }
3081 
QueryDisplayAttributes(VADisplayAttribute * attribList,int32_t * numAttribs)3082 VAStatus MediaLibvaCaps::QueryDisplayAttributes(
3083             VADisplayAttribute *attribList,
3084             int32_t *numAttribs)
3085 {
3086     DDI_CHK_NULL(attribList, "Null attribList", VA_STATUS_ERROR_INVALID_PARAMETER);
3087     DDI_CHK_NULL(numAttribs, "Null num_attribs", VA_STATUS_ERROR_INVALID_PARAMETER);
3088     *numAttribs = 0;
3089 
3090     attribList->type = VADisplayAttribCopy;
3091     (*numAttribs) ++;
3092 
3093     return GetDisplayAttributes(attribList, *numAttribs);
3094 }
3095 
GetDisplayAttributes(VADisplayAttribute * attribList,int32_t numAttribs)3096 VAStatus MediaLibvaCaps::GetDisplayAttributes(
3097             VADisplayAttribute *attribList,
3098             int32_t numAttribs)
3099 {
3100     DDI_CHK_NULL(attribList, "Null attribList", VA_STATUS_ERROR_INVALID_PARAMETER);
3101     for(auto i = 0; i < numAttribs; i ++)
3102     {
3103         switch(attribList->type)
3104         {
3105             case VADisplayAttribCopy:
3106                 attribList->min_value = attribList->value = attribList->max_value = 0;
3107                 attribList->flags = VA_DISPLAY_ATTRIB_GETTABLE;
3108                 break;
3109             default:
3110                 attribList->min_value = VA_ATTRIB_NOT_SUPPORTED;
3111                 attribList->max_value = VA_ATTRIB_NOT_SUPPORTED;
3112                 attribList->value = VA_ATTRIB_NOT_SUPPORTED;
3113                 attribList->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
3114                 break;
3115         }
3116         attribList ++;
3117     }
3118     return VA_STATUS_SUCCESS;
3119 }
3120 
IsVc1Profile(VAProfile profile)3121 bool MediaLibvaCaps::IsVc1Profile(VAProfile profile)
3122 {
3123     return (
3124             (profile == VAProfileVC1Advanced)        ||
3125             (profile == VAProfileVC1Main)            ||
3126             (profile == VAProfileVC1Simple)
3127            );
3128 }
3129 
IsAvcProfile(VAProfile profile)3130 bool MediaLibvaCaps::IsAvcProfile(VAProfile profile)
3131 {
3132     return (
3133             (profile == VAProfileH264ConstrainedBaseline) ||
3134             (profile == VAProfileH264Main) ||
3135             (profile == VAProfileH264High)
3136            );
3137 }
3138 
IsMpeg2Profile(VAProfile profile)3139 bool MediaLibvaCaps::IsMpeg2Profile(VAProfile profile)
3140 {
3141     return (
3142             (profile == VAProfileMPEG2Simple) ||
3143             (profile == VAProfileMPEG2Main)
3144            );
3145 }
3146 
IsVp8Profile(VAProfile profile)3147 bool MediaLibvaCaps::IsVp8Profile(VAProfile profile)
3148 {
3149     return (profile == VAProfileVP8Version0_3);
3150 }
3151 
IsVp9Profile(VAProfile profile)3152 bool MediaLibvaCaps::IsVp9Profile(VAProfile profile)
3153 {
3154     return (
3155             (profile == VAProfileVP9Profile0) ||
3156             (profile == VAProfileVP9Profile2) ||
3157             (profile == VAProfileVP9Profile1) ||
3158             (profile == VAProfileVP9Profile3)
3159             );
3160 }
3161 
IsHevcProfile(VAProfile profile)3162 bool MediaLibvaCaps::IsHevcProfile(VAProfile profile)
3163 {
3164     return (
3165             (profile == VAProfileHEVCMain)       ||
3166             (profile == VAProfileHEVCMain10)     ||
3167             (profile == VAProfileHEVCMain12)     ||
3168             (profile == VAProfileHEVCMain422_10) ||
3169             (profile == VAProfileHEVCMain422_12) ||
3170             (profile == VAProfileHEVCMain444)    ||
3171             (profile == VAProfileHEVCMain444_10) ||
3172             (profile == VAProfileHEVCMain444_12)
3173            );
3174 }
3175 
IsJpegProfile(VAProfile profile)3176 bool MediaLibvaCaps::IsJpegProfile(VAProfile profile)
3177 {
3178     return (profile == VAProfileJPEGBaseline);
3179 }
3180 
IsEncFei(VAEntrypoint entrypoint,uint32_t feiFunction)3181 bool MediaLibvaCaps::IsEncFei(VAEntrypoint entrypoint, uint32_t feiFunction)
3182 {
3183     if ((feiFunction & VA_FEI_FUNCTION_ENC_PAK)  ||
3184             (feiFunction == VA_FEI_FUNCTION_ENC) ||
3185             (feiFunction == VA_FEI_FUNCTION_PAK) ||
3186             (feiFunction == (VA_FEI_FUNCTION_ENC | VA_FEI_FUNCTION_PAK)) ||
3187             (entrypoint == VAEntrypointStats))
3188     {
3189         return true;
3190     }
3191     return false;
3192 }
3193 
GetEncodeCodecFunction(VAProfile profile,VAEntrypoint entrypoint,uint32_t feiFunction)3194 CODECHAL_FUNCTION MediaLibvaCaps::GetEncodeCodecFunction(VAProfile profile, VAEntrypoint entrypoint, uint32_t feiFunction)
3195 {
3196     CODECHAL_FUNCTION codecFunction;
3197     if (profile == VAProfileJPEGBaseline)
3198     {
3199         codecFunction = CODECHAL_FUNCTION_PAK;
3200     }
3201     else if (entrypoint == VAEntrypointEncSliceLP)
3202     {
3203         codecFunction = CODECHAL_FUNCTION_ENC_VDENC_PAK;
3204     }
3205     else
3206     {
3207         codecFunction = CODECHAL_FUNCTION_ENC_PAK;
3208         /*
3209         //  FeiFunction bit 0: FEI_ENC_INTEL
3210         //                  1: FEI_PAK_INTEL
3211         //                  2: FEI_ENC_PAK_INTEL
3212         //
3213         //  +---+---+---+
3214         //  | 2 | 1 | 0 |  FeiFunction [2:0]
3215         //  +---+---+---+
3216         //
3217         //  b000 means ENC_PAK
3218         */
3219         if (feiFunction & VA_FEI_FUNCTION_ENC_PAK)
3220         {
3221             codecFunction = CODECHAL_FUNCTION_FEI_ENC_PAK;
3222         }
3223         else if (feiFunction == VA_FEI_FUNCTION_ENC)
3224         {
3225             codecFunction = CODECHAL_FUNCTION_FEI_ENC;
3226         }
3227         else if (feiFunction == VA_FEI_FUNCTION_PAK)
3228         {
3229             codecFunction = CODECHAL_FUNCTION_FEI_PAK;
3230         }
3231         else if (feiFunction == (VA_FEI_FUNCTION_ENC | VA_FEI_FUNCTION_PAK))
3232         {
3233             // codecFunction in context keeps FEI_ENC_PAK if input is ENC|PAK
3234             codecFunction = CODECHAL_FUNCTION_FEI_ENC_PAK;
3235         }
3236         else if (entrypoint == VAEntrypointStats)
3237         {
3238             codecFunction = CODECHAL_FUNCTION_FEI_PRE_ENC;
3239         }
3240     }
3241     return codecFunction;
3242 }
3243 
GetEncodeCodecMode(VAProfile profile,VAEntrypoint entrypoint)3244 CODECHAL_MODE MediaLibvaCaps::GetEncodeCodecMode(VAProfile profile, VAEntrypoint entrypoint)
3245 {
3246     if (entrypoint == VAEntrypointStats)
3247     {
3248         return  CODECHAL_ENCODE_MODE_AVC;
3249     }
3250 
3251     switch (profile)
3252     {
3253         case VAProfileH264High:
3254         case VAProfileH264Main:
3255         case VAProfileH264ConstrainedBaseline:
3256             return CODECHAL_ENCODE_MODE_AVC;
3257         case VAProfileMPEG2Main:
3258         case VAProfileMPEG2Simple:
3259             return CODECHAL_ENCODE_MODE_MPEG2;
3260         case VAProfileJPEGBaseline:
3261             return CODECHAL_ENCODE_MODE_JPEG;
3262         case VAProfileVP8Version0_3:
3263             return CODECHAL_ENCODE_MODE_VP8;
3264         case VAProfileVP9Profile0:
3265             return CODECHAL_ENCODE_MODE_VP9;
3266         case VAProfileHEVCMain:
3267         case VAProfileHEVCMain10:
3268         case VAProfileHEVCMain12:
3269         case VAProfileHEVCMain422_10:
3270         case VAProfileHEVCMain422_12:
3271             return CODECHAL_ENCODE_MODE_HEVC;
3272         default:
3273             DDI_ASSERTMESSAGE("Invalid Encode Mode");
3274             return CODECHAL_UNSUPPORTED_MODE;
3275     }
3276 }
3277 
GetDecodeCodecMode(VAProfile profile)3278 CODECHAL_MODE MediaLibvaCaps::GetDecodeCodecMode(VAProfile profile)
3279 {
3280     switch (profile)
3281     {
3282         case VAProfileH264High:
3283         case VAProfileH264Main:
3284         case VAProfileH264ConstrainedBaseline:
3285             return CODECHAL_DECODE_MODE_AVCVLD;
3286         case VAProfileMPEG2Main:
3287         case VAProfileMPEG2Simple:
3288             return CODECHAL_DECODE_MODE_MPEG2VLD;
3289         case VAProfileJPEGBaseline:
3290             return CODECHAL_DECODE_MODE_JPEG;
3291         case VAProfileVP8Version0_3:
3292             return CODECHAL_DECODE_MODE_VP8VLD;
3293         case VAProfileVP9Profile0:
3294         case VAProfileVP9Profile1:
3295         case VAProfileVP9Profile2:
3296         case VAProfileVP9Profile3:
3297             return CODECHAL_DECODE_MODE_VP9VLD;
3298         case VAProfileHEVCMain:
3299         case VAProfileHEVCMain10:
3300         case VAProfileHEVCMain12:
3301         case VAProfileHEVCMain422_10:
3302         case VAProfileHEVCMain422_12:
3303         case VAProfileHEVCMain444:
3304         case VAProfileHEVCMain444_10:
3305         case VAProfileHEVCMain444_12:
3306             return CODECHAL_DECODE_MODE_HEVCVLD;
3307         case VAProfileVC1Simple:
3308         case VAProfileVC1Main:
3309         case VAProfileVC1Advanced:
3310                 return CODECHAL_DECODE_MODE_VC1VLD;
3311         default:
3312             DDI_ASSERTMESSAGE("Invalid Encode Mode");
3313             return CODECHAL_UNSUPPORTED_MODE;
3314     }
3315 }
3316 
GetDecodeCodecKey(VAProfile profile)3317 std::string MediaLibvaCaps::GetDecodeCodecKey(VAProfile profile)
3318 {
3319     switch (profile)
3320     {
3321         case VAProfileH264High:
3322         case VAProfileH264Main:
3323         case VAProfileH264ConstrainedBaseline:
3324             return DECODE_ID_AVC;
3325         case VAProfileMPEG2Main:
3326         case VAProfileMPEG2Simple:
3327             return DECODE_ID_MPEG2;
3328         case VAProfileJPEGBaseline:
3329             return DECODE_ID_JPEG;
3330         case VAProfileVP8Version0_3:
3331             return DECODE_ID_VP8;
3332         case VAProfileVP9Profile0:
3333         case VAProfileVP9Profile1:
3334         case VAProfileVP9Profile2:
3335         case VAProfileVP9Profile3:
3336             return DECODE_ID_VP9;
3337         case VAProfileHEVCMain:
3338         case VAProfileHEVCMain10:
3339             return DECODE_ID_HEVC;
3340         case VAProfileVC1Simple:
3341         case VAProfileVC1Main:
3342         case VAProfileVC1Advanced:
3343             return DECODE_ID_VC1;
3344         default:
3345             DDI_ASSERTMESSAGE("Invalid Encode Mode");
3346             return DECODE_ID_NONE;
3347     }
3348 }
3349 
GetEncodeCodecKey(VAProfile profile,VAEntrypoint entrypoint,uint32_t feiFunction)3350 std::string MediaLibvaCaps::GetEncodeCodecKey(VAProfile profile, VAEntrypoint entrypoint, uint32_t feiFunction)
3351 {
3352     switch (profile)
3353     {
3354         case VAProfileH264High:
3355         case VAProfileH264Main:
3356         case VAProfileH264ConstrainedBaseline:
3357             if (IsEncFei(entrypoint, feiFunction))
3358             {
3359                 return ENCODE_ID_AVCFEI;
3360             }
3361             else
3362             {
3363                 return ENCODE_ID_AVC;
3364             }
3365         case VAProfileMPEG2Main:
3366         case VAProfileMPEG2Simple:
3367             return ENCODE_ID_MPEG2;
3368         case VAProfileJPEGBaseline:
3369             return ENCODE_ID_JPEG;
3370         case VAProfileVP8Version0_3:
3371             return ENCODE_ID_VP8;
3372         case VAProfileVP9Profile0:
3373             return ENCODE_ID_VP9;
3374         case VAProfileHEVCMain:
3375         case VAProfileHEVCMain10:
3376         case VAProfileHEVCMain12:
3377         case VAProfileHEVCMain422_10:
3378         case VAProfileHEVCMain422_12:
3379             if (IsEncFei(entrypoint, feiFunction))
3380             {
3381                 return ENCODE_ID_HEVCFEI;
3382             }
3383             else
3384             {
3385                 return ENCODE_ID_HEVC;
3386             }
3387         case VAProfileNone:
3388             if (IsEncFei(entrypoint, feiFunction))
3389             {
3390                 return ENCODE_ID_AVCFEI;
3391             }
3392             else
3393             {
3394                 return ENCODE_ID_NONE;
3395             }
3396         default:
3397             return ENCODE_ID_NONE;
3398     }
3399 }
3400 
IsDecConfigId(VAConfigID configId)3401 bool MediaLibvaCaps::IsDecConfigId(VAConfigID configId)
3402 {
3403     return ((configId >= DDI_CODEC_GEN_CONFIG_ATTRIBUTES_DEC_BASE) &&
3404             (configId < (DDI_CODEC_GEN_CONFIG_ATTRIBUTES_DEC_BASE + m_decConfigs.size())));
3405 }
3406 
IsEncConfigId(VAConfigID configId)3407 bool MediaLibvaCaps::IsEncConfigId(VAConfigID configId)
3408 {
3409     return ((configId >= DDI_CODEC_GEN_CONFIG_ATTRIBUTES_ENC_BASE) &&
3410             (configId < (DDI_CODEC_GEN_CONFIG_ATTRIBUTES_ENC_BASE + m_encConfigs.size())));
3411 }
3412 
IsVpConfigId(VAConfigID configId)3413 bool MediaLibvaCaps::IsVpConfigId(VAConfigID configId)
3414 {
3415     return ((configId >= DDI_VP_GEN_CONFIG_ATTRIBUTES_BASE) &&
3416             (configId < (DDI_VP_GEN_CONFIG_ATTRIBUTES_BASE + m_vpConfigs.size())));
3417 }
3418 
3419 
GetCpCaps()3420 MediaLibvaCapsCpInterface* MediaLibvaCaps::GetCpCaps()
3421 {
3422     return m_CapsCp;
3423 }
3424 
IsMfeSupportedEntrypoint(VAEntrypoint entrypoint)3425 bool MediaLibvaCaps::IsMfeSupportedEntrypoint(VAEntrypoint entrypoint)
3426 {
3427     if (entrypoint != VAEntrypointEncSlice &&           //MFE only support Encode slice
3428         entrypoint != VAEntrypointFEI )                 //and FEI yet
3429     {
3430         return false;
3431     }
3432 
3433     return true;
3434 }
3435 
IsMfeSupportedProfile(VAProfile profile)3436 bool MediaLibvaCaps::IsMfeSupportedProfile(VAProfile profile)
3437 {
3438     if (profile != VAProfileH264Main &&                  // MFE only support AVC now
3439         profile != VAProfileH264High &&
3440         profile != VAProfileH264ConstrainedBaseline)
3441     {
3442         return false;
3443     }
3444 
3445     return true;
3446 }
3447 
DestroyConfig(VAConfigID configId)3448 VAStatus MediaLibvaCaps::DestroyConfig(VAConfigID configId)
3449 {
3450     if ( IsDecConfigId(configId) || IsEncConfigId(configId) || IsVpConfigId(configId) ||
3451          (m_CapsCp && m_CapsCp->IsCpConfigId(configId)) )
3452     {
3453         return VA_STATUS_SUCCESS;
3454     }
3455 
3456     return VA_STATUS_ERROR_INVALID_CONFIG;
3457 }
3458 
ConvertMediaFmtToGmmFmt(DDI_MEDIA_FORMAT format)3459 GMM_RESOURCE_FORMAT MediaLibvaCaps::ConvertMediaFmtToGmmFmt(
3460     DDI_MEDIA_FORMAT format)
3461 {
3462     switch (format)
3463     {
3464         case Media_Format_X8R8G8B8   : return GMM_FORMAT_B8G8R8X8_UNORM_TYPE;
3465         case Media_Format_A8R8G8B8   : return GMM_FORMAT_B8G8R8A8_UNORM_TYPE;
3466         case Media_Format_X8B8G8R8   : return GMM_FORMAT_R8G8B8X8_UNORM_TYPE;
3467         case Media_Format_A8B8G8R8   : return GMM_FORMAT_R8G8B8A8_UNORM_TYPE;
3468         case Media_Format_R8G8B8A8   : return GMM_FORMAT_R8G8B8A8_UNORM_TYPE;
3469         case Media_Format_R5G6B5     : return GMM_FORMAT_B5G6R5_UNORM_TYPE;
3470         case Media_Format_R8G8B8     : return GMM_FORMAT_R8G8B8_UNORM;
3471         case Media_Format_RGBP       : return GMM_FORMAT_RGBP;
3472         case Media_Format_BGRP       : return GMM_FORMAT_BGRP;
3473         case Media_Format_NV12       : return GMM_FORMAT_NV12_TYPE;
3474         case Media_Format_NV21       : return GMM_FORMAT_NV21_TYPE;
3475         case Media_Format_AYUV       : return GMM_FORMAT_AYUV_TYPE;
3476         case Media_Format_YUY2       : return GMM_FORMAT_YUY2;
3477         case Media_Format_UYVY       : return GMM_FORMAT_UYVY;
3478         case Media_Format_YV12       : return GMM_FORMAT_YV12_TYPE;
3479         case Media_Format_IYUV       : return GMM_FORMAT_IYUV_TYPE;
3480         case Media_Format_I420       : return GMM_FORMAT_I420_TYPE;
3481         case Media_Format_444P       : return GMM_FORMAT_MFX_JPEG_YUV444_TYPE;
3482         case Media_Format_422H       : return GMM_FORMAT_MFX_JPEG_YUV422H_TYPE;
3483         case Media_Format_411P       : return GMM_FORMAT_MFX_JPEG_YUV411_TYPE;
3484         case Media_Format_422V       : return GMM_FORMAT_MFX_JPEG_YUV422V_TYPE;
3485         case Media_Format_IMC3       : return GMM_FORMAT_IMC3_TYPE;
3486         case Media_Format_400P       : return GMM_FORMAT_GENERIC_8BIT;
3487         case Media_Format_Buffer     : return GMM_FORMAT_RENDER_8BIT;
3488         case Media_Format_P010       : return GMM_FORMAT_P010_TYPE;
3489         case Media_Format_P012       : return GMM_FORMAT_P016_TYPE;
3490         case Media_Format_P016       : return GMM_FORMAT_P016_TYPE;
3491         case Media_Format_Y210       : return GMM_FORMAT_Y210_TYPE;
3492         case Media_Format_Y216       : return GMM_FORMAT_Y216_TYPE;
3493         case Media_Format_Y410       : return GMM_FORMAT_Y410_TYPE;
3494         case Media_Format_Y416       : return GMM_FORMAT_Y416_TYPE;
3495         case Media_Format_R10G10B10A2: return GMM_FORMAT_R10G10B10A2_UNORM_TYPE;
3496         case Media_Format_B10G10R10A2: return GMM_FORMAT_B10G10R10A2_UNORM_TYPE;
3497         case Media_Format_R10G10B10X2: return GMM_FORMAT_R10G10B10A2_UNORM_TYPE;
3498         case Media_Format_B10G10R10X2: return GMM_FORMAT_B10G10R10A2_UNORM_TYPE;
3499 #if VA_CHECK_VERSION(1, 9, 0)
3500         case Media_Format_Y212       : return GMM_FORMAT_Y212_TYPE;
3501         case Media_Format_Y412       : return GMM_FORMAT_Y412_TYPE;
3502 #endif
3503 #if VA_CHECK_VERSION(1, 13, 0)
3504         case Media_Format_XYUV       : return GMM_FORMAT_AYUV_TYPE;
3505 #endif
3506         default                      : return GMM_FORMAT_INVALID;
3507     }
3508 }
3509 
ConvertFourccToGmmFmt(uint32_t fourcc)3510 GMM_RESOURCE_FORMAT MediaLibvaCaps::ConvertFourccToGmmFmt(uint32_t fourcc)
3511 {
3512     switch (fourcc)
3513     {
3514         case VA_FOURCC_BGRA   : return GMM_FORMAT_B8G8R8A8_UNORM_TYPE;
3515         case VA_FOURCC_ARGB   : return GMM_FORMAT_B8G8R8A8_UNORM_TYPE;
3516         case VA_FOURCC_RGBA   : return GMM_FORMAT_R8G8B8A8_UNORM_TYPE;
3517         case VA_FOURCC_ABGR   : return GMM_FORMAT_R8G8B8A8_UNORM_TYPE;
3518         case VA_FOURCC_BGRX   : return GMM_FORMAT_B8G8R8X8_UNORM_TYPE;
3519         case VA_FOURCC_XRGB   : return GMM_FORMAT_B8G8R8X8_UNORM_TYPE;
3520         case VA_FOURCC_RGBX   : return GMM_FORMAT_R8G8B8X8_UNORM_TYPE;
3521         case VA_FOURCC_XBGR   : return GMM_FORMAT_R8G8B8X8_UNORM_TYPE;
3522         case VA_FOURCC_R8G8B8 : return GMM_FORMAT_R8G8B8_UNORM;
3523         case VA_FOURCC_RGBP   : return GMM_FORMAT_RGBP;
3524         case VA_FOURCC_BGRP   : return GMM_FORMAT_BGRP;
3525         case VA_FOURCC_RGB565 : return GMM_FORMAT_B5G6R5_UNORM_TYPE;
3526         case VA_FOURCC_AYUV   : return GMM_FORMAT_AYUV_TYPE;
3527 #if VA_CHECK_VERSION(1, 13, 0)
3528         case VA_FOURCC_XYUV   : return GMM_FORMAT_AYUV_TYPE;
3529 #endif
3530         case VA_FOURCC_NV12   : return GMM_FORMAT_NV12_TYPE;
3531         case VA_FOURCC_NV21   : return GMM_FORMAT_NV21_TYPE;
3532         case VA_FOURCC_YUY2   : return GMM_FORMAT_YUY2;
3533         case VA_FOURCC_UYVY   : return GMM_FORMAT_UYVY;
3534         case VA_FOURCC_YV12   : return GMM_FORMAT_YV12_TYPE;
3535         case VA_FOURCC_I420   : return GMM_FORMAT_I420_TYPE;
3536         case VA_FOURCC_IYUV   : return GMM_FORMAT_IYUV_TYPE;
3537         case VA_FOURCC_411P   : return GMM_FORMAT_MFX_JPEG_YUV411_TYPE;
3538         case VA_FOURCC_422H   : return GMM_FORMAT_MFX_JPEG_YUV422H_TYPE;
3539         case VA_FOURCC_422V   : return GMM_FORMAT_MFX_JPEG_YUV422V_TYPE;
3540         case VA_FOURCC_444P   : return GMM_FORMAT_MFX_JPEG_YUV444_TYPE;
3541         case VA_FOURCC_IMC3   : return GMM_FORMAT_IMC3_TYPE;
3542         case VA_FOURCC_P208   : return GMM_FORMAT_P208_TYPE;
3543         case VA_FOURCC_P010   : return GMM_FORMAT_P010_TYPE;
3544         case VA_FOURCC_P012   : return GMM_FORMAT_P016_TYPE;
3545         case VA_FOURCC_P016   : return GMM_FORMAT_P016_TYPE;
3546         case VA_FOURCC_Y210   : return GMM_FORMAT_Y210_TYPE;
3547         case VA_FOURCC_Y410   : return GMM_FORMAT_Y410_TYPE;
3548 #if VA_CHECK_VERSION(1, 9, 0)
3549         case VA_FOURCC_Y212   : return GMM_FORMAT_Y212_TYPE;
3550 #endif
3551         case VA_FOURCC_Y216   : return GMM_FORMAT_Y216_TYPE;
3552 #if VA_CHECK_VERSION(1, 9, 0)
3553         case VA_FOURCC_Y412   : return GMM_FORMAT_Y412_TYPE;
3554 #endif
3555         case VA_FOURCC_Y416   : return GMM_FORMAT_Y416_TYPE;
3556         case VA_FOURCC_Y800   : return GMM_FORMAT_GENERIC_8BIT;
3557         case VA_FOURCC_A2R10G10B10   : return GMM_FORMAT_R10G10B10A2_UNORM_TYPE;
3558         case VA_FOURCC_A2B10G10R10   : return GMM_FORMAT_B10G10R10A2_UNORM_TYPE;
3559         case VA_FOURCC_X2R10G10B10   : return GMM_FORMAT_R10G10B10A2_UNORM_TYPE;
3560         case VA_FOURCC_X2B10G10R10   : return GMM_FORMAT_B10G10R10A2_UNORM_TYPE;
3561         default               : return GMM_FORMAT_INVALID;
3562     }
3563 }
3564 
IsMfeSupportedOnPlatform(const PLATFORM & platform)3565 bool MediaLibvaCaps::IsMfeSupportedOnPlatform(const PLATFORM &platform)
3566 {
3567     return (GFX_IS_PRODUCT(platform, IGFX_SKYLAKE));
3568 }
3569 
GetMbProcessingRateDec(MEDIA_FEATURE_TABLE * skuTable,uint32_t * mbProcessingRatePerSec)3570 VAStatus MediaLibvaCaps::GetMbProcessingRateDec(
3571         MEDIA_FEATURE_TABLE *skuTable,
3572         uint32_t *mbProcessingRatePerSec)
3573 {
3574     uint32_t idx = 0;
3575 
3576     DDI_CHK_NULL(skuTable, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
3577     DDI_CHK_NULL(mbProcessingRatePerSec, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
3578 
3579     const uint32_t mb_rate[2] =
3580     {
3581         // non-ULX, ULX/Atom
3582         4800000, 3600000
3583     };
3584 
3585     if (MEDIA_IS_SKU(skuTable, FtrLCIA) || //Atom
3586             MEDIA_IS_SKU(skuTable, FtrULX)) // ULX
3587     {
3588         idx = 1;
3589     }
3590     else
3591     {
3592         // Default is non-ULX
3593         idx = 0;
3594     }
3595 
3596     *mbProcessingRatePerSec = mb_rate[idx];
3597     return VA_STATUS_SUCCESS;
3598 }
3599 
GetMbProcessingRateEnc(MEDIA_FEATURE_TABLE * skuTable,uint32_t tuIdx,uint32_t codecMode,bool vdencActive,uint32_t * mbProcessingRatePerSec)3600 VAStatus MediaLibvaCaps::GetMbProcessingRateEnc(
3601         MEDIA_FEATURE_TABLE *skuTable,
3602         uint32_t tuIdx,
3603         uint32_t codecMode,
3604         bool vdencActive,
3605         uint32_t *mbProcessingRatePerSec)
3606 {
3607     DDI_CHK_NULL(skuTable, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
3608     DDI_CHK_NULL(mbProcessingRatePerSec, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
3609 
3610     uint32_t gtIdx = 0;
3611 
3612     // Calculate the GT index based on GT type
3613     if (MEDIA_IS_SKU(skuTable, FtrGT1))
3614     {
3615         gtIdx = 4;
3616     }
3617     else if (MEDIA_IS_SKU(skuTable, FtrGT1_5))
3618     {
3619         gtIdx = 3;
3620     }
3621     else if (MEDIA_IS_SKU(skuTable, FtrGT2))
3622     {
3623         gtIdx = 2;
3624     }
3625     else if (MEDIA_IS_SKU(skuTable, FtrGT3))
3626     {
3627         gtIdx = 1;
3628     }
3629     else if (MEDIA_IS_SKU(skuTable, FtrGT4))
3630     {
3631         gtIdx = 0;
3632     }
3633     else
3634     {
3635         return VA_STATUS_ERROR_INVALID_PARAMETER;
3636     }
3637 
3638     if (MEDIA_IS_SKU(skuTable, FtrULX))
3639     {
3640         static const uint32_t mbRate[7][5] =
3641         {
3642             // GT4 | GT3 |  GT2   | GT1.5  |  GT1
3643             { 0, 0, 1029393, 1029393, 676280 },
3644             { 0, 0, 975027, 975027, 661800 },
3645             { 0, 0, 776921, 776921, 640000 },
3646             { 0, 0, 776921, 776921, 640000 },
3647             { 0, 0, 776921, 776921, 640000 },
3648             { 0, 0, 416051, 416051, 317980 },
3649             { 0, 0, 214438, 214438, 180655 }
3650         };
3651 
3652         if (gtIdx == 0 || gtIdx == 1)
3653         {
3654             return VA_STATUS_ERROR_INVALID_PARAMETER;
3655         }
3656         *mbProcessingRatePerSec = mbRate[tuIdx][gtIdx];
3657     }
3658     else if (MEDIA_IS_SKU(skuTable, FtrULT))
3659     {
3660         static const uint32_t defaultult_mb_rate[7][5] =
3661         {
3662             // GT4    | GT3   |  GT2   | GT1.5   |  GT1
3663             { 1544090, 1544090, 1544090, 1029393, 676280 },
3664             { 1462540, 1462540, 1462540, 975027, 661800 },
3665             { 1165381, 1165381, 1165381, 776921, 640000 },
3666             { 1165381, 1165381, 1165381, 776921, 640000 },
3667             { 1165381, 1165381, 1165381, 776921, 640000 },
3668             { 624076, 624076, 624076, 416051, 317980 },
3669             { 321657, 321657, 321657, 214438, 180655 }
3670         };
3671 
3672         *mbProcessingRatePerSec = defaultult_mb_rate[tuIdx][gtIdx];
3673     }
3674     else
3675     {
3676         // regular
3677         const uint32_t default_mb_rate[7][5] =
3678         {
3679             // GT4    | GT3   |   GT2  | GT1.5  |  GT1
3680             { 1544090, 1544090, 1544090, 1029393, 676280 },
3681             { 1462540, 1462540, 1462540, 975027, 661800 },
3682             { 1165381, 1165381, 1165381, 776921, 640000 },
3683             { 1165381, 1165381, 1165381, 776921, 640000 },
3684             { 1165381, 1165381, 1165381, 776921, 640000 },
3685             { 624076, 624076, 624076, 416051, 317980 },
3686             { 321657, 321657, 321657, 214438, 180655 }
3687         };
3688 
3689         *mbProcessingRatePerSec = default_mb_rate[tuIdx][gtIdx];
3690     }
3691     return VA_STATUS_SUCCESS;
3692 }
3693 
CreateMediaLibvaCaps(DDI_MEDIA_CONTEXT * mediaCtx)3694 MediaLibvaCaps * MediaLibvaCaps::CreateMediaLibvaCaps(DDI_MEDIA_CONTEXT *mediaCtx)
3695 {
3696     if (mediaCtx != nullptr)
3697     {
3698 
3699         MediaLibvaCaps * Caps = CapsFactory::CreateCaps(
3700             (uint32_t)mediaCtx->platform.eProductFamily + MEDIA_EXT_FLAG, mediaCtx);
3701 
3702         if(Caps == nullptr)
3703         {
3704             Caps = CapsFactory::CreateCaps((uint32_t)mediaCtx->platform.eProductFamily, mediaCtx);
3705         }
3706 
3707         return Caps;
3708 
3709     }
3710     else
3711     {
3712         return nullptr;
3713     }
3714 }
3715 
GetSurfaceModifier(DDI_MEDIA_SURFACE * mediaSurface,uint64_t & modifier)3716 VAStatus MediaLibvaCaps::GetSurfaceModifier(DDI_MEDIA_SURFACE* mediaSurface, uint64_t &modifier)
3717 {
3718     DDI_CHK_NULL(mediaSurface,                   "nullptr mediaSurface",                   VA_STATUS_ERROR_INVALID_SURFACE);
3719     DDI_CHK_NULL(mediaSurface->bo,               "nullptr mediaSurface->bo",               VA_STATUS_ERROR_INVALID_SURFACE);
3720     DDI_CHK_NULL(mediaSurface->pGmmResourceInfo, "nullptr mediaSurface->pGmmResourceInfo", VA_STATUS_ERROR_INVALID_SURFACE);
3721     GMM_TILE_TYPE  gmmTileType = mediaSurface->pGmmResourceInfo->GetTileType();
3722     GMM_RESOURCE_FLAG       GmmFlags    = {0};
3723     GmmFlags = mediaSurface->pGmmResourceInfo->GetResFlags();
3724 
3725     bool                    bMmcEnabled = false;
3726     if ((GmmFlags.Gpu.MMC               ||
3727         GmmFlags.Gpu.CCS)               &&
3728         (GmmFlags.Info.MediaCompressed ||
3729          GmmFlags.Info.RenderCompressed))
3730     {
3731         bMmcEnabled = true;
3732     }
3733     else
3734     {
3735         bMmcEnabled = false;
3736     }
3737 
3738     switch(gmmTileType)
3739     {
3740         case GMM_TILED_Y:
3741             if (m_mediaCtx->m_auxTableMgr && bMmcEnabled)
3742             {
3743                 modifier = GmmFlags.Info.MediaCompressed ? I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS :
3744 -                 (GmmFlags.Info.RenderCompressed ? I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS : I915_FORMAT_MOD_Y_TILED);
3745             }
3746             else
3747             {
3748                 modifier = I915_FORMAT_MOD_Y_TILED;
3749             }
3750             break;
3751         case GMM_TILED_X:
3752             modifier = I915_FORMAT_MOD_X_TILED;
3753             break;
3754         case GMM_NOT_TILED:
3755             modifier = DRM_FORMAT_MOD_NONE;
3756             break;
3757         default:
3758             //handle other possible tile format
3759             if(I915_TILING_Y == mediaSurface->TileType)
3760             {
3761                 modifier = GmmFlags.Info.MediaCompressed ? I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS :
3762 -                 (GmmFlags.Info.RenderCompressed ? I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS : I915_FORMAT_MOD_Y_TILED);
3763             }
3764             else
3765             {
3766                 modifier = DRM_FORMAT_MOD_NONE;
3767             }
3768             break;
3769 
3770     }
3771     return VA_STATUS_SUCCESS;
3772 }
3773 
SetExternalSurfaceTileFormat(DDI_MEDIA_SURFACE * mediaSurface,uint32_t & tileformat,bool & bMemCompEnable,bool & bMemCompRC)3774 VAStatus MediaLibvaCaps::SetExternalSurfaceTileFormat(DDI_MEDIA_SURFACE* mediaSurface,
3775                                                       uint32_t &tileformat, bool &bMemCompEnable, bool &bMemCompRC)
3776 {
3777     DDI_CHK_NULL(mediaSurface,                     "nullptr mediaSurface",                     VA_STATUS_ERROR_INVALID_SURFACE);
3778     DDI_CHK_NULL(mediaSurface->pSurfDesc,          "nullptr mediaSurface->pSurfDesc",          VA_STATUS_ERROR_INVALID_SURFACE);
3779 
3780     switch (mediaSurface->pSurfDesc->modifier)
3781     {
3782         case DRM_FORMAT_MOD_LINEAR:
3783             tileformat = I915_TILING_NONE;
3784             bMemCompEnable = false;
3785             break;
3786         case I915_FORMAT_MOD_X_TILED:
3787             tileformat = I915_TILING_X;
3788             bMemCompEnable = false;
3789             break;
3790         case I915_FORMAT_MOD_Y_TILED:
3791         case I915_FORMAT_MOD_Yf_TILED:
3792             tileformat = I915_TILING_Y;
3793             bMemCompEnable = false;
3794             break;
3795         case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
3796             tileformat = I915_TILING_Y;
3797             bMemCompEnable = true;
3798             bMemCompRC = true;
3799             break;
3800         case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
3801             tileformat = I915_TILING_Y;
3802             bMemCompEnable = true;
3803             bMemCompRC = false;
3804             break;
3805         default:
3806             return VA_STATUS_ERROR_INVALID_SURFACE;
3807     }
3808 
3809     return VA_STATUS_SUCCESS;
3810 }
3811