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_g9.cpp
24 //! \brief This file implements the C++ class/interface for gen9 media capbilities.
25 //!
26
27 #include "codec_def_encode_hevc.h"
28 #include "media_libva_util.h"
29 #include "media_libva.h"
30 #include "media_libva_caps_cp_interface.h"
31 #include "media_libva_caps_g9.h"
32 #include "media_libva_caps_factory.h"
33
34 const VAImageFormat m_supportedImageformatsG9[] =
35 { {VA_FOURCC_BGRA, VA_LSB_FIRST, 32, 32, 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff}, /* [31:0] B:G:R:A 8:8:8:8 little endian */
36 {VA_FOURCC_RGBA, VA_LSB_FIRST, 32, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff}, /* [31:0] R:G:B:A 8:8:8:8 little endian */
37 {VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x0000ff00, 0x00ff0000, 0xff000000, 0}, /* [31:0] B:G:R:x 8:8:8:8 little endian */
38 {VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0xff000000, 0x00ff0000, 0x0000ff00, 0}, /* [31:0] R:G:B:x 8:8:8:8 little endian */
39 {VA_FOURCC_A2R10G10B10, VA_LSB_FIRST, 32, 30, 0x3ff00000, 0x000ffc00, 0x000003ff, 0x30000000}, /* [31:0] A:R:G:B 2:10:10:10 little endian */
40 {VA_FOURCC_A2B10G10R10, VA_LSB_FIRST, 32, 30, 0x000003ff, 0x000ffc00, 0x3ff00000, 0x30000000}, /* [31:0] A:B:G:R 2:10:10:10 little endian */
41 {VA_FOURCC_X2R10G10B10, VA_LSB_FIRST, 32, 30, 0x3ff00000, 0x000ffc00, 0x000003ff, 0}, /* [31:0] X:R:G:B 2:10:10:10 little endian */
42 {VA_FOURCC_X2B10G10R10, VA_LSB_FIRST, 32, 30, 0x000003ff, 0x000ffc00, 0x3ff00000, 0}, /* [31:0] X:B:G:R 2:10:10:10 little endian */
43 {VA_FOURCC_RGB565, VA_LSB_FIRST, 16, 16, 0xf800, 0x07e0, 0x001f, 0}, /* [15:0] R:G:B 5:6:5 little endian */
44 {VA_FOURCC_RGBP, VA_LSB_FIRST, 24, 24,0,0,0,0},
45 {VA_FOURCC_BGRP, VA_LSB_FIRST, 24, 24,0,0,0,0},
46 {VA_FOURCC_AYUV, VA_LSB_FIRST, 32, 0,0,0,0,0},
47 {VA_FOURCC_Y800, VA_LSB_FIRST, 8, 0,0,0,0,0},
48 {VA_FOURCC_NV12, VA_LSB_FIRST, 12, 0,0,0,0,0},
49 {VA_FOURCC_NV21, VA_LSB_FIRST, 12, 0,0,0,0,0},
50 {VA_FOURCC_YUY2, VA_LSB_FIRST, 16, 0,0,0,0,0},
51 {VA_FOURCC_UYVY, VA_LSB_FIRST, 16, 0,0,0,0,0},
52 {VA_FOURCC_YV12, VA_LSB_FIRST, 12, 0,0,0,0,0},
53 {VA_FOURCC_I420, VA_LSB_FIRST, 12, 0,0,0,0,0},
54 {VA_FOURCC_411P, VA_LSB_FIRST, 12, 0,0,0,0,0},
55 {VA_FOURCC_422H, VA_LSB_FIRST, 16, 0,0,0,0,0},
56 {VA_FOURCC_422V, VA_LSB_FIRST, 16, 0,0,0,0,0},
57 {VA_FOURCC_444P, VA_LSB_FIRST, 24, 0,0,0,0,0},
58 {VA_FOURCC_IMC3, VA_LSB_FIRST, 16, 0,0,0,0,0},
59 {VA_FOURCC_P010, VA_LSB_FIRST, 24, 0,0,0,0,0}
60 };
61
QueryImageFormats(VAImageFormat * formatList,int32_t * numFormats)62 VAStatus MediaLibvaCapsG9::QueryImageFormats(VAImageFormat *formatList, int32_t *numFormats)
63 {
64 DDI_CHK_NULL(formatList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
65 DDI_CHK_NULL(numFormats, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
66 int32_t num = 0;
67 uint32_t maxNum = GetImageFormatsMaxNum();
68
69 memset(formatList, 0, sizeof(m_supportedImageformatsG9));
70 for (uint32_t idx = 0; idx < maxNum; idx++)
71 {
72 formatList[num].fourcc = m_supportedImageformatsG9[idx].fourcc;
73 formatList[num].byte_order = m_supportedImageformatsG9[idx].byte_order;
74 formatList[num].bits_per_pixel = m_supportedImageformatsG9[idx].bits_per_pixel;
75 formatList[num].depth = m_supportedImageformatsG9[idx].depth;
76 formatList[num].red_mask = m_supportedImageformatsG9[idx].red_mask;
77 formatList[num].green_mask = m_supportedImageformatsG9[idx].green_mask;
78 formatList[num].blue_mask = m_supportedImageformatsG9[idx].blue_mask;
79 formatList[num].alpha_mask = m_supportedImageformatsG9[idx].alpha_mask;
80 num++;
81 }
82 *numFormats = num;
83
84 return VA_STATUS_SUCCESS;
85 }
86
GetImageFormatsMaxNum()87 uint32_t MediaLibvaCapsG9::GetImageFormatsMaxNum()
88 {
89 return sizeof(m_supportedImageformatsG9)/sizeof(m_supportedImageformatsG9[0]);
90 }
91
IsImageSupported(uint32_t fourcc)92 bool MediaLibvaCapsG9::IsImageSupported(uint32_t fourcc)
93 {
94 uint32_t maxNum = GetImageFormatsMaxNum();
95 for (int32_t idx = 0; idx < maxNum; idx++)
96 {
97 if (m_supportedImageformatsG9[idx].fourcc == fourcc)
98 {
99 return true;
100 }
101 }
102
103 return false;
104 }
105
PopulateColorMaskInfo(VAImageFormat * vaImgFmt)106 VAStatus MediaLibvaCapsG9::PopulateColorMaskInfo(VAImageFormat *vaImgFmt)
107 {
108 uint32_t maxNum = GetImageFormatsMaxNum();
109
110 DDI_CHK_NULL(vaImgFmt, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
111
112 for (int32_t idx = 0; idx < maxNum; idx++)
113 {
114 if (m_supportedImageformatsG9[idx].fourcc == vaImgFmt->fourcc)
115 {
116 vaImgFmt->red_mask = m_supportedImageformatsG9[idx].red_mask;
117 vaImgFmt->green_mask = m_supportedImageformatsG9[idx].green_mask;
118 vaImgFmt->blue_mask = m_supportedImageformatsG9[idx].blue_mask;
119 vaImgFmt->alpha_mask = m_supportedImageformatsG9[idx].alpha_mask;
120
121 return VA_STATUS_SUCCESS;
122 }
123 }
124
125 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
126 }
127
GetPlatformSpecificAttrib(VAProfile profile,VAEntrypoint entrypoint,VAConfigAttribType type,uint32_t * value)128 VAStatus MediaLibvaCapsG9::GetPlatformSpecificAttrib(VAProfile profile,
129 VAEntrypoint entrypoint,
130 VAConfigAttribType type,
131 uint32_t *value)
132 {
133 DDI_CHK_NULL(value, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
134 VAStatus status = VA_STATUS_SUCCESS;
135 *value = VA_ATTRIB_NOT_SUPPORTED;
136 switch ((int)type)
137 {
138 case VAConfigAttribEncMaxRefFrames:
139 {
140 if (entrypoint == VAEntrypointEncSliceLP || !IsHevcProfile(profile))
141 {
142 status = VA_STATUS_ERROR_INVALID_PARAMETER;
143 }
144 else
145 {
146 *value = ENCODE_DP_HEVC_NUM_MAX_VME_L0_REF_G9 | (ENCODE_DP_HEVC_NUM_MAX_VME_L1_REF_G9 << 16);;
147 }
148 break;
149 }
150 case VAConfigAttribDecProcessing:
151 {
152 if (IsAvcProfile(profile) || IsHevcProfile(profile))
153 {
154 *value = VA_DEC_PROCESSING;
155 }
156 else
157 {
158 *value = VA_DEC_PROCESSING_NONE;
159 }
160 break;
161 }
162 case VAConfigAttribEncIntraRefresh:
163 {
164 if(IsAvcProfile(profile))
165 {
166 *value = VA_ENC_INTRA_REFRESH_ROLLING_COLUMN |
167 VA_ENC_INTRA_REFRESH_ROLLING_ROW;
168 }
169 else if(entrypoint == VAEntrypointEncSlice && IsHevcProfile(profile))
170 {
171 *value = VA_ENC_INTRA_REFRESH_ROLLING_COLUMN;
172 }
173 else
174 {
175 *value = VA_ENC_INTRA_REFRESH_NONE;
176 }
177 break;
178 }
179 case VAConfigAttribEncROI:
180 {
181 VAConfigAttribValEncROI roi_attr = { .value = 0 };
182
183 if (entrypoint == VAEntrypointEncSliceLP)
184 {
185 status = VA_STATUS_ERROR_INVALID_PARAMETER;
186 }
187 else if (IsAvcProfile(profile))
188 {
189 // the capacity is differnt for CQP and BRC mode, set it as larger one here
190 roi_attr.bits.num_roi_regions = ENCODE_DP_AVC_MAX_ROI_NUM_BRC;
191 roi_attr.bits.roi_rc_priority_support = 0;
192 roi_attr.bits.roi_rc_qp_delta_support = 1;
193 }
194 else if (IsHevcProfile(profile))
195 {
196 roi_attr.bits.num_roi_regions = ENCODE_DP_HEVC_MAX_NUM_ROI;
197 roi_attr.bits.roi_rc_priority_support = 0;
198 roi_attr.bits.roi_rc_qp_delta_support = 1;
199 }
200
201 *value = roi_attr.value;
202 break;
203 }
204 case VAConfigAttribCustomRoundingControl:
205 {
206 if (IsAvcProfile(profile))
207 {
208 *value = 1;
209 }
210 else
211 {
212 *value = 0;
213 }
214 break;
215 }
216 case VAConfigAttribEncMaxSlices:
217 {
218 if (entrypoint == VAEntrypointEncSlice && IsHevcProfile(profile))
219 {
220 *value = CODECHAL_HEVC_MAX_NUM_SLICES_LVL_5;
221 }
222 else
223 {
224 *value =0;
225 status = VA_STATUS_ERROR_INVALID_PARAMETER;
226 }
227 break;
228 }
229 case VAConfigAttribMaxPictureWidth:
230 {
231 if(profile == VAProfileJPEGBaseline)
232 {
233 *value = ENCODE_JPEG_MAX_PIC_WIDTH;
234 }
235 else if(IsHevcProfile(profile) || IsAvcProfile(profile) || IsVp8Profile(profile))
236 {
237 *value = CODEC_4K_MAX_PIC_WIDTH;
238 }
239 else
240 {
241 *value = CODEC_MAX_PIC_WIDTH;
242 }
243 break;
244 }
245 case VAConfigAttribMaxPictureHeight:
246 {
247 if(profile == VAProfileJPEGBaseline)
248 {
249 *value = ENCODE_JPEG_MAX_PIC_HEIGHT;
250 }
251 else if(IsHevcProfile(profile) || IsAvcProfile(profile) || IsVp8Profile(profile))
252 {
253 *value = CODEC_4K_MAX_PIC_HEIGHT;
254 }
255 else
256 {
257 *value = CODEC_MAX_PIC_HEIGHT;
258 }
259 break;
260 }
261 default:
262 status = VA_STATUS_ERROR_INVALID_PARAMETER;
263 break;
264 }
265 return status;
266 }
267
LoadProfileEntrypoints()268 VAStatus MediaLibvaCapsG9::LoadProfileEntrypoints()
269 {
270 VAStatus status = VA_STATUS_SUCCESS;
271 status = LoadAvcDecProfileEntrypoints();
272 DDI_CHK_RET(status, "Failed to initialize Caps!");
273 status = LoadAvcEncProfileEntrypoints();
274 DDI_CHK_RET(status, "Failed to initialize Caps!");
275 status = LoadAvcEncLpProfileEntrypoints();
276 DDI_CHK_RET(status, "Failed to initialize Caps!");
277 status = LoadMpeg2DecProfileEntrypoints();
278 DDI_CHK_RET(status, "Failed to initialize Caps!");
279 status = LoadMpeg2EncProfileEntrypoints();
280 DDI_CHK_RET(status, "Failed to initialize Caps!");
281 status = LoadVc1DecProfileEntrypoints();
282 DDI_CHK_RET(status, "Failed to initialize Caps!");
283 status = LoadJpegDecProfileEntrypoints();
284 DDI_CHK_RET(status, "Failed to initialize Caps!");
285 status = LoadJpegEncProfileEntrypoints();
286 DDI_CHK_RET(status, "Failed to initialize Caps!");
287 status = LoadHevcDecProfileEntrypoints();
288 DDI_CHK_RET(status, "Failed to initialize Caps!");
289 status = LoadHevcEncProfileEntrypoints();
290 DDI_CHK_RET(status, "Failed to initialize Caps!");
291 status = LoadVp8DecProfileEntrypoints();
292 DDI_CHK_RET(status, "Failed to initialize Caps!");
293 status = LoadVp8EncProfileEntrypoints();
294 DDI_CHK_RET(status, "Failed to initialize Caps!");
295 status = LoadVp9DecProfileEntrypoints();
296 DDI_CHK_RET(status, "Failed to initialize Caps!");
297 status = LoadVp9EncProfileEntrypoints();
298 DDI_CHK_RET(status, "Failed to initialize Caps!");
299 #if !defined(_FULL_OPEN_SOURCE) && defined(ENABLE_KERNELS)
300 status = LoadNoneProfileEntrypoints();
301 DDI_CHK_RET(status, "Failed to initialize Caps!");
302 #endif
303 status = m_CapsCp->LoadCpProfileEntrypoints();
304 DDI_CHK_RET(status, "Failed to initialize CP Caps!");
305 return status;
306 }
307
QueryAVCROIMaxNum(uint32_t rcMode,bool isVdenc,uint32_t * maxNum,bool * isRoiInDeltaQP)308 VAStatus MediaLibvaCapsG9::QueryAVCROIMaxNum(uint32_t rcMode, bool isVdenc, uint32_t *maxNum, bool *isRoiInDeltaQP)
309 {
310 DDI_CHK_NULL(maxNum, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
311 DDI_CHK_NULL(isRoiInDeltaQP, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
312
313 if(isVdenc)
314 {
315 *maxNum = ENCODE_VDENC_AVC_MAX_ROI_NUMBER_G9;
316 }
317 else
318 {
319 switch (rcMode)
320 {
321 case VA_RC_CQP:
322 *maxNum = ENCODE_DP_AVC_MAX_ROI_NUMBER;
323 break;
324 default:
325 *maxNum = ENCODE_DP_AVC_MAX_ROI_NUM_BRC;
326 break;
327 }
328 }
329
330 *isRoiInDeltaQP = true;
331 return VA_STATUS_SUCCESS;
332 }
333