1 /*
2 * Copyright (c) 2017-2018, 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     mhw_vdbox_mfx_interface.cpp
24 //! \brief    MHW interface for constructing MFX commands for the Vdbox engine
25 //! \details  Defines the interfaces for constructing MHW Vdbox MFX commands across all platforms
26 //!
27 
28 #include "mhw_vdbox_mfx_interface.h"
29 
30 const uint8_t MhwVdboxMfxInterface::m_mpeg2QuantMatrixScan[64] =
31 {
32     // Inverse Zig-Zag scan pattern
33     0, 1, 5, 6, 14, 15, 27, 28,
34     2, 4, 7, 13, 16, 26, 29, 42,
35     3, 8, 12, 17, 25, 30, 41, 43,
36     9, 11, 18, 24, 31, 40, 44, 53,
37     10, 19, 23, 32, 39, 45, 52, 54,
38     20, 22, 33, 38, 46, 51, 55, 60,
39     21, 34, 37, 47, 50, 56, 59, 61,
40     35, 36, 48, 49, 57, 58, 62, 63
41 };
42 
43 const uint16_t MhwVdboxMfxInterface::m_mpeg2DefaultIntraQuantizerMatrix[64] =
44 {
45     8, 16, 19, 22, 26, 27, 29, 34,
46     16, 16, 22, 24, 27, 29, 34, 37,
47     19, 22, 26, 27, 29, 34, 34, 38,
48     22, 22, 26, 27, 29, 34, 37, 40,
49     22, 26, 27, 29, 32, 35, 40, 48,
50     26, 27, 29, 32, 35, 40, 48, 58,
51     26, 27, 29, 34, 38, 46, 56, 69,
52     27, 29, 35, 38, 46, 56, 69, 83
53 };
54 
55 const uint16_t MhwVdboxMfxInterface::m_mpeg2DefaultNonIntraQuantizerMatrix[64] =
56 {
57     16, 16, 16, 16, 16, 16, 16, 16,
58     16, 16, 16, 16, 16, 16, 16, 16,
59     16, 16, 16, 16, 16, 16, 16, 16,
60     16, 16, 16, 16, 16, 16, 16, 16,
61     16, 16, 16, 16, 16, 16, 16, 16,
62     16, 16, 16, 16, 16, 16, 16, 16,
63     16, 16, 16, 16, 16, 16, 16, 16,
64     16, 16, 16, 16, 16, 16, 16, 16
65 };
66 
67 const uint32_t MhwVdboxMfxInterface::m_mpeg2SliceDeltaQPMax[4] =
68 {
69     0x02040608, 0x01020304, 0x01020304, 0x01010202
70 };
71 
72 const uint32_t MhwVdboxMfxInterface::m_mpeg2InitSliceDeltaQPMin[4] =
73 {
74     0x81828384, 0x81828384, 0x81828384, 0x81828384
75 };
76 
77 const uint32_t MhwVdboxMfxInterface::m_mpeg2FrameBitrateMinMax[4] =
78 {
79     0x00010000, 0x00010000, 0x00010000, 0x00010000
80 };
81 
82 const uint32_t MhwVdboxMfxInterface::m_mpeg2FrameBitrateMinMaxDelta[4] =
83 {
84     0x00010000, 0x00010000, 0x00010000, 0x00010000
85 };
86 
87 const uint8_t MhwVdboxMfxInterface::m_columnScan4x4[16] =
88 {
89     0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15
90 };
91 
92 const uint8_t MhwVdboxMfxInterface::m_columnScan8x8[64] =
93 {
94     0, 8, 16, 24, 32, 40, 48, 56, 1, 9, 17, 25, 33, 41, 49, 57,
95     2, 10, 18, 26, 34, 42, 50, 58, 3, 11, 19, 27, 35, 43, 51, 59,
96     4, 12, 20, 28, 36, 44, 52, 60, 5, 13, 21, 29, 37, 45, 53, 61,
97     6, 14, 22, 30, 38, 46, 54, 62, 7, 15, 23, 31, 39, 47, 55, 63
98 };
99 
100 const MhwVdboxMfxInterface::AvcSliceType MhwVdboxMfxInterface::m_AvcBsdSliceType[10] =
101 {
102     MhwVdboxMfxInterface::avcSliceP,
103     MhwVdboxMfxInterface::avcSliceB,
104     MhwVdboxMfxInterface::avcSliceI,
105     MhwVdboxMfxInterface::avcSliceP,
106     MhwVdboxMfxInterface::avcSliceI,
107     MhwVdboxMfxInterface::avcSliceP,
108     MhwVdboxMfxInterface::avcSliceB,
109     MhwVdboxMfxInterface::avcSliceI,
110     MhwVdboxMfxInterface::avcSliceP,
111     MhwVdboxMfxInterface::avcSliceI
112 };
113 
114 const MhwVdboxMfxInterface::VDEncFrameDeltaTable MhwVdboxMfxInterface::m_vdEncFrameDelta100PercentTab[CODEC_AVC_NUM_QP] =
115 {
116     { 1400, 1400 },
117     { 1400, 1400 },
118     { 1400, 1400 },
119     { 1400, 1400 },
120     { 1400, 1400 },
121     { 1400, 1400 },
122     { 1400, 1400 },
123     { 1400, 1400 },
124     { 1400, 1400 },
125     { 1400, 1400 },
126     { 1400, 1400 },
127     { 1400, 1400 },
128     { 1400, 1400 },
129     { 1400, 1400 },
130     { 1400, 1400 },
131     { 1400, 1400 },
132     { 1300, 1400 },
133     { 1275, 1325 },
134     { 1250, 1275 },
135     { 1200, 1200 },
136     { 1125, 1125 },
137     { 1075, 1075 },
138     { 1000, 1000 },
139     { 800, 950 },
140     { 725, 900 },
141     { 650, 850 },
142     { 600, 800 },
143     { 575, 750 },
144     { 500, 700 },
145     { 425, 675 },
146     { 375, 650 },
147     { 350, 625 },
148     { 325, 550 },
149     { 275, 500 },
150     { 250, 450 },
151     { 225, 425 },
152     { 200, 375 },
153     { 180, 350 },
154     { 170, 320 },
155     { 160, 290 },
156     { 150, 260 },
157     { 140, 245 },
158     { 125, 230 },
159     { 110, 220 },
160     { 110, 220 },
161     { 110, 220 },
162     { 110, 220 },
163     { 110, 220 },
164     { 110, 220 },
165     { 110, 220 },
166     { 110, 220 },
167     { 110, 220 }
168 };
169 
170 const MhwVdboxMfxInterface::VDEncFrameDeltaTable MhwVdboxMfxInterface::m_vdEncFrameDelta90PercentTab[CODEC_AVC_NUM_QP] =
171 {
172     { 1400, 1400 },
173     { 1400, 1400 },
174     { 1400, 1400 },
175     { 1400, 1400 },
176     { 1400, 1400 },
177     { 1400, 1400 },
178     { 1400, 1400 },
179     { 1400, 1400 },
180     { 1400, 1400 },
181     { 1400, 1400 },
182     { 960, 1400 },
183     { 900, 1400 },
184     { 840, 1300 },
185     { 770, 1200 },
186     { 710, 1100 },
187     { 650, 1000 },
188     { 590, 900 },
189     { 560, 860 },
190     { 530, 815 },
191     { 500, 750 },
192     { 470, 700 },
193     { 430, 650 },
194     { 400, 600 },
195     { 380, 570 },
196     { 350, 540 },
197     { 320, 500 },
198     { 285, 465 },
199     { 270, 430 },
200     { 250, 400 },
201     { 235, 380 },
202     { 215, 360 },
203     { 200, 350 },
204     { 180, 320 },
205     { 160, 290 },
206     { 140, 260 },
207     { 130, 240 },
208     { 115, 220 },
209     { 100, 200 },
210     { 100, 200 },
211     { 100, 200 },
212     { 100, 200 },
213     { 100, 200 },
214     { 100, 200 },
215     { 100, 200 },
216     { 100, 200 },
217     { 100, 200 },
218     { 100, 200 },
219     { 100, 200 },
220     { 100, 200 },
221     { 100, 200 },
222     { 100, 200 },
223     { 100, 200 }
224 };
225 
MhwVdboxMfxInterface(PMOS_INTERFACE osInterface,MhwMiInterface * miInterface,MhwCpInterface * cpInterface,bool decodeInUse)226 MhwVdboxMfxInterface::MhwVdboxMfxInterface(
227     PMOS_INTERFACE osInterface,
228     MhwMiInterface *miInterface,
229     MhwCpInterface *cpInterface,
230     bool decodeInUse)
231 {
232     MHW_FUNCTION_ENTER;
233 
234     m_osInterface = osInterface;
235     m_MiInterface = miInterface;
236     m_cpInterface = cpInterface;
237     m_decodeInUse = decodeInUse;
238 
239     MHW_ASSERT(m_osInterface);
240     MHW_ASSERT(m_MiInterface);
241     MHW_ASSERT(m_cpInterface);
242 
243     m_waTable = osInterface->pfnGetWaTable(osInterface);
244     m_skuTable = osInterface->pfnGetSkuTable(osInterface);
245     m_osInterface->pfnGetPlatform(m_osInterface, &m_platform);
246     m_maxVdboxIndex = MEDIA_IS_SKU(m_skuTable, FtrVcs2) ? MHW_VDBOX_NODE_2 : MHW_VDBOX_NODE_1;
247 
248     if (m_osInterface->bUsesGfxAddress)
249     {
250         AddResourceToCmd = Mhw_AddResourceToCmd_GfxAddress;
251     }
252     else // bUsesPatchList
253     {
254         AddResourceToCmd = Mhw_AddResourceToCmd_PatchList;
255     }
256 
257     auto gtSystemInfo = m_osInterface->pfnGetGtSystemInfo(m_osInterface);
258 
259     if (gtSystemInfo != nullptr && (!MEDIA_IS_SKU(m_skuTable, FtrWithSlimVdbox) || m_decodeInUse))
260     {
261         m_numVdbox = (uint8_t)(gtSystemInfo->VDBoxInfo.NumberOfVDBoxEnabled);
262     }
263     else
264     {
265         m_numVdbox = 1;
266     }
267 }
268 
CalcAvcImgStateMinMaxBitrate(MHW_VDBOX_AVC_IMG_BITRATE_PARAMS & params)269 void MhwVdboxMfxInterface::CalcAvcImgStateMinMaxBitrate(
270     MHW_VDBOX_AVC_IMG_BITRATE_PARAMS& params)
271 {
272     // Set this to New mode (= 1) - FrameBitRateMaxUnit and FrameBitRateMinUnit are in new mode (32byte/4Kb)
273     params.frameBitRateMaxUnitMode = params.frameBitRateMinUnitMode = 1;
274 
275     // Set this to Kilo Byte (= 1) - FrameBitRateMax and FrameBitRateMin are in units of 4KBytes when FrameBitrateMaxUnitMode and FrameBitRateMinUnitMode are set to 1
276     params.frameBitRateMaxUnit = params.frameBitRateMinUnit = 1;
277 
278     // We have 14 bits available when FrameBitRateMaxUnitMode is set to 1, so set it to max value
279     params.frameBitRateMax = (1 << 14) - 1;
280 
281     // Set this to min available value
282     params.frameBitRateMin = 0;
283 
284     // Set frame bitrate max and min delta to 0
285     params.frameBitRateMaxDelta = params.frameBitRateMinDelta = 0;
286 
287     return;
288 }
289 
GetViewOrder(PMHW_VDBOX_AVC_DPB_PARAMS params,uint32_t currIdx,uint32_t list)290 uint32_t MhwVdboxMfxInterface::GetViewOrder(
291     PMHW_VDBOX_AVC_DPB_PARAMS params,
292     uint32_t currIdx,
293     uint32_t list)
294 {
295     MHW_CHK_NULL_RETURN(params);
296 
297     auto avcPicParams = params->pAvcPicParams;
298     auto mvcExtPicParams = params->pMvcExtPicParams;
299     auto avcRefList = params->ppAvcRefList;
300 
301     // No need to check if bottom field since only progressive is supported
302     int32_t  currPOC = avcPicParams->CurrFieldOrderCnt[0];
303     uint32_t numRefs = (list == LIST_0) ? mvcExtPicParams->NumInterViewRefsL0 : mvcExtPicParams->NumInterViewRefsL1;
304     uint32_t viewOrder = 0xF;
305     uint32_t currRef = params->pAvcPicIdx[currIdx].ucPicIdx;
306 
307     if (params->pAvcPicIdx[currIdx].bValid &&
308         avcRefList[currRef]->bUsedAsInterViewRef &&
309         (currPOC == avcRefList[currRef]->iFieldOrderCnt[0]))
310     {
311         for (uint32_t i = 0; i < numRefs; i++)
312         {
313             if (mvcExtPicParams->ViewIDList[currIdx] == mvcExtPicParams->InterViewRefList[list][i])
314             {
315                 viewOrder = mvcExtPicParams->ViewIDList[currIdx];
316                 break;
317             }
318         }
319     }
320 
321     return viewOrder;
322 }
323 
IsVc1IPicture(const CODEC_PICTURE & picture,bool isFirstField,uint16_t picType)324 bool MhwVdboxMfxInterface::IsVc1IPicture(
325     const CODEC_PICTURE& picture,
326     bool isFirstField,
327     uint16_t picType)
328 {
329     bool isI = false;
330 
331     if (CodecHal_PictureIsField(picture))
332     {
333         if (picType == vc1IIField)
334         {
335             // I/I frame
336             isI = true;
337         }
338         else if (picType == vc1IPField)
339         {
340             // I/P frame
341             isI = isFirstField;
342         }
343         else if (picType == vc1PIField)
344         {
345             // P/I frame
346             isI = (!isFirstField);
347         }
348     }
349     else
350     {
351         isI = (picType == vc1IFrame);
352     }
353 
354     return isI;
355 }
356 
IsVc1PPicture(const CODEC_PICTURE & picture,bool isFirstField,uint16_t picType)357 bool MhwVdboxMfxInterface::IsVc1PPicture(
358     const CODEC_PICTURE& picture,
359     bool isFirstField,
360     uint16_t picType)
361 {
362     bool isP = false;
363 
364     if (CodecHal_PictureIsField(picture))
365     {
366         if (picType == vc1PPField)
367         {
368             // P/P frame
369             isP = true;
370         }
371         else if (picType == vc1IPField)
372         {
373             // I/P frame
374             isP = (!isFirstField);
375         }
376         else if (picType == vc1PIField)
377         {
378             // P/I frame
379             isP = isFirstField;
380         }
381     }
382     else
383     {
384         isP = (picType == vc1PFrame);
385     }
386 
387     return isP;
388 }
389 
IsVc1BPicture(const CODEC_PICTURE & picture,bool isFirstField,uint16_t picType)390 bool MhwVdboxMfxInterface::IsVc1BPicture(
391     const CODEC_PICTURE& picture,
392     bool isFirstField,
393     uint16_t picType)
394 {
395     bool isB = false;
396 
397     if (CodecHal_PictureIsField(picture))
398     {
399         if (picType == vc1BBIField)
400         {
401             // B/BI frame
402             isB = isFirstField;
403         }
404         else if (picType == vc1BIBField)
405         {
406             // BI/B frame
407             isB = (!isFirstField);
408         }
409         else if (picType == vc1BBField)
410         {
411             // BI/BI frame
412             isB = true;
413         }
414     }
415     else
416     {
417         isB = (picType == vc1BFrame);
418     }
419 
420     return isB;
421 }
422 
IsVc1BIPicture(const CODEC_PICTURE & picture,bool isFirstField,uint16_t picType)423 bool MhwVdboxMfxInterface::IsVc1BIPicture(
424     const CODEC_PICTURE& picture,
425     bool isFirstField,
426     uint16_t picType)
427 {
428     bool isBI = false;
429 
430     if (CodecHal_PictureIsField(picture))
431     {
432         if (picType == vc1BBIField)
433         {
434             // B/BI frame
435             isBI = (!isFirstField);
436         }
437         else if (picType == vc1BIBField)
438         {
439             // BI/B frame
440             isBI = isFirstField;
441         }
442         else if (picType == vc1BIBIField)
443         {
444             // BI/BI frame
445             isBI = true;
446         }
447     }
448     else
449     {
450         isBI = (picType == vc1BIFrame);
451     }
452 
453     return isBI;
454 }
455 
AddMfxAvcImgCmd(PMOS_COMMAND_BUFFER cmdBuffer,PMHW_BATCH_BUFFER batchBuffer,PMHW_VDBOX_AVC_IMG_PARAMS params)456 MOS_STATUS MhwVdboxMfxInterface::AddMfxAvcImgCmd(
457     PMOS_COMMAND_BUFFER cmdBuffer,
458     PMHW_BATCH_BUFFER batchBuffer,
459     PMHW_VDBOX_AVC_IMG_PARAMS params)
460 {
461     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
462 
463     MHW_FUNCTION_ENTER;
464 
465     if (m_decodeInUse)
466     {
467         MHW_MI_CHK_STATUS(AddMfxDecodeAvcImgCmd(cmdBuffer, batchBuffer, params));
468     }
469     else
470     {
471         MHW_MI_CHK_STATUS(AddMfxEncodeAvcImgCmd(cmdBuffer, batchBuffer, params));
472     }
473 
474     return eStatus;
475 }
476 
AddMfxAvcWeightOffset(PMOS_COMMAND_BUFFER cmdBuffer,PMHW_BATCH_BUFFER batchBuffer,PMHW_VDBOX_AVC_WEIGHTOFFSET_PARAMS params)477 MOS_STATUS MhwVdboxMfxInterface::AddMfxAvcWeightOffset(
478     PMOS_COMMAND_BUFFER cmdBuffer,
479     PMHW_BATCH_BUFFER batchBuffer,
480     PMHW_VDBOX_AVC_WEIGHTOFFSET_PARAMS params)
481 {
482     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
483 
484     MHW_FUNCTION_ENTER;
485 
486     if (m_decodeInUse)
487     {
488         MHW_MI_CHK_STATUS(AddMfxDecodeAvcWeightOffset(cmdBuffer, batchBuffer, params));
489     }
490     else
491     {
492         MHW_MI_CHK_STATUS(AddMfxEncodeAvcWeightOffset(cmdBuffer, batchBuffer, params));
493     }
494 
495     return eStatus;
496 }
497 
AddMfxAvcSlice(PMOS_COMMAND_BUFFER cmdBuffer,PMHW_BATCH_BUFFER batchBuffer,PMHW_VDBOX_AVC_SLICE_STATE avcSliceState)498 MOS_STATUS MhwVdboxMfxInterface::AddMfxAvcSlice(
499     PMOS_COMMAND_BUFFER cmdBuffer,
500     PMHW_BATCH_BUFFER batchBuffer,
501     PMHW_VDBOX_AVC_SLICE_STATE avcSliceState)
502 {
503     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
504 
505     MHW_FUNCTION_ENTER;
506 
507     if (m_decodeInUse)
508     {
509         MHW_MI_CHK_STATUS(AddMfxDecodeAvcSlice(cmdBuffer, batchBuffer, avcSliceState));
510     }
511     else
512     {
513         MHW_MI_CHK_STATUS(AddMfxEncodeAvcSlice(cmdBuffer, batchBuffer, avcSliceState));
514     }
515 
516     return eStatus;
517 }
518 
AddMfxMpeg2PicCmd(PMOS_COMMAND_BUFFER cmdBuffer,PMHW_VDBOX_MPEG2_PIC_STATE params)519 MOS_STATUS MhwVdboxMfxInterface::AddMfxMpeg2PicCmd(
520     PMOS_COMMAND_BUFFER cmdBuffer,
521     PMHW_VDBOX_MPEG2_PIC_STATE params)
522 {
523     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
524 
525     MHW_FUNCTION_ENTER;
526 
527     if (m_decodeInUse)
528     {
529         MHW_MI_CHK_STATUS(AddMfxDecodeMpeg2PicCmd(cmdBuffer, params));
530     }
531     else
532     {
533         MHW_MI_CHK_STATUS(AddMfxEncodeMpeg2PicCmd(cmdBuffer, params));
534     }
535 
536     return eStatus;
537 }
538 
AddMfxVp8PicCmd(PMOS_COMMAND_BUFFER cmdBuffer,PMHW_VDBOX_VP8_PIC_STATE params)539 MOS_STATUS MhwVdboxMfxInterface::AddMfxVp8PicCmd(
540     PMOS_COMMAND_BUFFER cmdBuffer,
541     PMHW_VDBOX_VP8_PIC_STATE params)
542 {
543     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
544 
545     MHW_FUNCTION_ENTER;
546 
547     if (m_decodeInUse)
548     {
549         MHW_MI_CHK_STATUS(AddMfxDecodeVp8PicCmd(cmdBuffer, params));
550     }
551     else
552     {
553         MHW_MI_CHK_STATUS(AddMfxEncodeVp8PicCmd(cmdBuffer, params));
554     }
555 
556     return eStatus;
557 }
558 
GetJpegDecodeFormat(MOS_FORMAT format)559 MHW_VDBOX_DECODE_JPEG_FORMAT_CODE MhwVdboxMfxInterface::GetJpegDecodeFormat(MOS_FORMAT format)
560 {
561     switch (format)
562     {
563     case Format_NV12:
564         return MHW_VDBOX_DECODE_JPEG_FORMAT_NV12;
565     case Format_UYVY:
566         return MHW_VDBOX_DECODE_JPEG_FORMAT_UYVY;
567     case Format_YUY2:
568         return MHW_VDBOX_DECODE_JPEG_FORMAT_YUY2;
569     default:
570         return MHW_VDBOX_DECODE_JPEG_FORMAT_SEPARATE_PLANE;
571     }
572 
573     return MHW_VDBOX_DECODE_JPEG_FORMAT_SEPARATE_PLANE;
574 }
575 
IsVPlanePresent(MOS_FORMAT format)576 bool MhwVdboxMfxInterface::IsVPlanePresent(MOS_FORMAT format)
577 {
578     switch (format)
579     {
580     case Format_NV12:
581     case Format_NV11:
582     case Format_P208:
583     case Format_IMC1:
584     case Format_IMC3:
585     case Format_YUY2:
586     case Format_YUYV:
587     case Format_YVYU:
588     case Format_UYVY:
589     case Format_VYUY:
590     case Format_422H:
591     case Format_422V:
592         // Adding RGB formats because RGB is treated like YUV for JPEG encode and decode
593     case Format_RGBP:
594     case Format_BGRP:
595     case Format_A8R8G8B8:
596     case Format_X8R8G8B8:
597     case Format_A8B8G8R8:
598     case Format_411P:
599     case Format_411R:
600     case Format_444P:
601     case Format_IMC2:
602     case Format_IMC4:
603         return true;
604     default:
605         return false;
606     }
607 }
608 
MosToMediaStateFormat(MOS_FORMAT format)609 uint32_t MhwVdboxMfxInterface::MosToMediaStateFormat(MOS_FORMAT format)
610 {
611     switch (format)
612     {
613     case Format_A8R8G8B8:
614     case Format_X8R8G8B8:
615     case Format_A8B8G8R8:
616         return MHW_MEDIASTATE_SURFACEFORMAT_R8G8B8A8_UNORM;
617     case Format_422H:
618     case Format_422V:
619         return MHW_MEDIASTATE_SURFACEFORMAT_PLANAR_422_8;
620     case Format_AYUV:
621     case Format_AUYV:
622         return MHW_MEDIASTATE_SURFACEFORMAT_A8Y8U8V8_UNORM;
623     case Format_NV12:
624     case Format_NV11:
625     case Format_P208:
626     case Format_IMC1:
627     case Format_IMC3:
628         return MHW_MEDIASTATE_SURFACEFORMAT_PLANAR_420_8;
629     case Format_400P:
630     case Format_P8:
631         return MHW_MEDIASTATE_SURFACEFORMAT_Y8_UNORM;
632     case Format_411P:
633     case Format_411R:
634         return MHW_MEDIASTATE_SURFACEFORMAT_PLANAR_411_8;
635     case Format_UYVY:
636         return MHW_MEDIASTATE_SURFACEFORMAT_YCRCB_SWAPY;
637     case Format_YVYU:
638         return MHW_MEDIASTATE_SURFACEFORMAT_YCRCB_SWAPUV;
639     case Format_VYUY:
640         return MHW_MEDIASTATE_SURFACEFORMAT_YCRCB_SWAPUVY;
641     case Format_YUY2:
642     case Format_YUYV:
643     case Format_444P:
644     case Format_IMC2:
645     case Format_IMC4:
646     default:
647         return MHW_MEDIASTATE_SURFACEFORMAT_YCRCB_NORMAL;
648     }
649 
650     return MHW_MEDIASTATE_SURFACEFORMAT_YCRCB_NORMAL;
651 }
652 
GetJpegHorizontalSamplingFactorForY(CodecEncodeJpegInputSurfaceFormat format)653 uint32_t MhwVdboxMfxInterface::GetJpegHorizontalSamplingFactorForY(
654     CodecEncodeJpegInputSurfaceFormat format)
655 {
656     uint32_t horizontalSamplingFactor = 1;
657 
658     if (format == codechalJpegY8)
659     {
660         horizontalSamplingFactor = 1;
661     }
662     else if (format == codechalJpegNV12)
663     {
664         horizontalSamplingFactor = 2;
665     }
666     else if (format == codechalJpegUYVY || format == codechalJpegYUY2)
667     {
668         horizontalSamplingFactor = 2;
669     }
670     else if (format == codechalJpegRGB)
671     {
672         horizontalSamplingFactor = 1;
673     }
674 
675     return horizontalSamplingFactor;
676 }
677 
GetJpegVerticalSamplingFactorForY(CodecEncodeJpegInputSurfaceFormat format)678 uint32_t MhwVdboxMfxInterface::GetJpegVerticalSamplingFactorForY(
679     CodecEncodeJpegInputSurfaceFormat format)
680 {
681     uint32_t verticalSamplingFactor = 1;
682 
683     if (format == codechalJpegY8)
684     {
685         verticalSamplingFactor = 1;
686     }
687     else if (format == codechalJpegNV12)
688     {
689         verticalSamplingFactor = 2;
690     }
691     else if (format == codechalJpegRGB ||
692         format == codechalJpegUYVY ||
693         format == codechalJpegYUY2)
694     {
695         verticalSamplingFactor = 1;
696     }
697 
698     return verticalSamplingFactor;
699 }
700