1 /*
2 * Copyright (c) 2018-2019, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 
23 //!
24 //! \file     media_libva_caps_g12.h
25 //! \brief    This file defines the C++ class/interface for gen12 media capbilities.
26 //!
27 
28 #ifndef __MEDIA_LIBVA_CAPS_G12_H__
29 #define __MEDIA_LIBVA_CAPS_G12_H__
30 
31 #include "media_libva_caps.h"
32 
33 //!
34 //! \class  MediaLibvaCapsG12
35 //! \brief  Media libva caps Gen12
36 //!
37 class MediaLibvaCapsG12 : public MediaLibvaCaps
38 {
39 public:
40     //!
41     //! \brief    Constructor
42     //!
MediaLibvaCapsG12(DDI_MEDIA_CONTEXT * mediaCtx)43     MediaLibvaCapsG12(DDI_MEDIA_CONTEXT *mediaCtx) : MediaLibvaCaps(mediaCtx)
44     {
45         // TGL supported Encode format
46         static struct EncodeFormatTable encodeFormatTableTGL[] =
47         {
48             {AVC, DualPipe, VA_RT_FORMAT_YUV420},
49             {AVC, Vdenc, VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_YUV444},
50             {HEVC, DualPipe, VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV420_10BPP},
51             {HEVC, Vdenc, VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV420_10BPP |
52              VA_RT_FORMAT_YUV444 | VA_RT_FORMAT_YUV444_10 | VA_RT_FORMAT_RGB32 |
53              VA_RT_FORMAT_RGB32_10BPP},
54             {VP9, Vdenc, VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV420_10BPP |
55              VA_RT_FORMAT_YUV444 | VA_RT_FORMAT_YUV444_10 | VA_RT_FORMAT_RGB32 |
56              VA_RT_FORMAT_RGB32_10BPP},
57         };
58         m_encodeFormatTable = (struct EncodeFormatTable*)(&encodeFormatTableTGL[0]);
59         m_encodeFormatCount = sizeof(encodeFormatTableTGL)/sizeof(struct EncodeFormatTable);
60         return;
61     }
62 
63     //!
Init()64     virtual VAStatus Init() override
65     {
66         return LoadProfileEntrypoints();
67     }
68 
69     virtual VAStatus QueryImageFormats(VAImageFormat *formatList, int32_t *num_formats) override;
70 
71     virtual uint32_t GetImageFormatsMaxNum() override;
72 
73     virtual bool IsImageSupported(uint32_t fourcc) override;
74 
75     //!
76     //! \brief    Populate the color masks info
77     //!
78     //! \param    [in,out] Image format
79     //!           Pointer to a VAImageFormat array. Color masks information will be populated to this
80     //!           structure.
81     //!
82     //! \return   VAStatus
83     //!           VA_STATUS_SUCCESS if succeed
84     //!
85     virtual VAStatus PopulateColorMaskInfo(VAImageFormat *vaImgFmt) override;
86 
87     //!
88     //! \brief    Return internal encode mode for given profile and entrypoint
89     //!
90     //! \param    [in] profile
91     //!           Specify the VAProfile
92     //!
93     //! \param    [in] entrypoint
94     //!           Specify the VAEntrypoint
95     //!
96     //! \return   Codehal mode
97     //!
98     CODECHAL_MODE GetEncodeCodecMode(VAProfile profile, VAEntrypoint entrypoint) override;
99 
100     //!
101     //! \brief    Return the decode codec key for given profile
102     //!
103     //! \param    [in] profile
104     //!           Specify the VAProfile
105     //!
106     //! \return   Std::string decode codec key
107     //!
108     virtual std::string GetDecodeCodecKey(VAProfile profile)                     override;
109 
110     //!
111     //! \brief    Return the encode codec key for given profile and entrypoint
112     //!
113     //! \param    [in] profile
114     //!           Specify the VAProfile
115     //!
116     //! \param    [in] entrypoint
117     //!           Specify the entrypoint
118     //!
119     //! \param    [in] feiFunction
120     //!           Specify the feiFunction
121     //!
122     //! \return   Std::string encode codec key
123     //!
124     std::string GetEncodeCodecKey(VAProfile profile,
125                                   VAEntrypoint entrypoint,
126                                   uint32_t feiFunction)                          override;
127 
128     virtual CODECHAL_MODE GetDecodeCodecMode(VAProfile profile)                  override;
129 
130     //!
131     //! \brief    Get surface attributes for a given config ID
132     //!
133     //! \param    [in] configId
134     //!           VA configuration
135     //!
136     //! \param    [in,out] attribList
137     //!           Pointer to VASurfaceAttrib array. It returns
138     //!           the supported  surface attributes
139     //!
140     //! \param    [in,out] numAttribs
141     //!           The number of elements allocated on input
142     //!           Return the number of elements actually filled in output
143     //!
144     //! \return   VAStatus
145     //!           VA_STATUS_SUCCESS if success
146     //!           VA_STATUS_ERROR_MAX_NUM_EXCEEDED if size of attribList is too small
147     //!
148     VAStatus QuerySurfaceAttributes(VAConfigID configId,
149                                     VASurfaceAttrib *attribList,
150                                     uint32_t *numAttribs)                        override;
151 
152     virtual bool IsHevcProfile(VAProfile profile)                                override;
153 
154     virtual GMM_RESOURCE_FORMAT ConvertMediaFmtToGmmFmt(DDI_MEDIA_FORMAT format) override;
155 
156 protected:
157     static const uint32_t m_maxHevcEncWidth =
158         CODEC_16K_MAX_PIC_WIDTH; //!< maxinum width for HEVC encode
159     static const uint32_t m_maxHevcEncHeight =
160         CODEC_12K_MAX_PIC_HEIGHT; //!< maxinum height for HEVC encode
161     static const uint32_t m_decHevcMax16kWidth =
162         CODEC_16K_MAX_PIC_WIDTH; //!< Maximum width for HEVC decode
163     static const uint32_t m_decHevcMax16kHeight =
164         CODEC_16K_MAX_PIC_HEIGHT; //!< Maximum height for HEVC decode
165     static const uint32_t m_decVp9Max16kWidth =
166         CODEC_16K_MAX_PIC_WIDTH; //!< Maximum width for VP9 decode
167     static const uint32_t m_decVp9Max16kHeight =
168         CODEC_16K_MAX_PIC_HEIGHT; //!< Maximum height for VP9 decode
169     static const uint32_t m_maxVp9EncWidth =
170         CODEC_8K_MAX_PIC_WIDTH; //!< maximum width for VP9 encode
171     static const uint32_t m_maxVp9EncHeight =
172         CODEC_8K_MAX_PIC_HEIGHT; //!< maximum height for VP9 encode
173     static const VAImageFormat m_G12ImageFormats[]; //!< Gen12 supported image formats
174     static const VAConfigAttribValEncRateControlExt m_encVp9RateControlExt; //!< External enc rate control caps for VP9 encode
175     virtual VAStatus GetPlatformSpecificAttrib(VAProfile profile,
176                                                VAEntrypoint entrypoint,
177                                                VAConfigAttribType type,
178                                                unsigned int *value) override;
179 
180     virtual VAStatus LoadProfileEntrypoints() override;
181     virtual VAStatus LoadJpegDecProfileEntrypoints();
182     virtual VAStatus LoadVp9EncProfileEntrypoints() override;
183     virtual VAStatus LoadHevcEncProfileEntrypoints() override;
184 
185     virtual VAStatus CheckEncodeResolution(
186         VAProfile profile,
187         uint32_t width,
188         uint32_t height) override;
189     virtual VAStatus CheckDecodeResolution(
190         int32_t codecMode,
191         VAProfile profile,
192         uint32_t width,
193         uint32_t height) override;
194     virtual VAStatus CreateEncAttributes(
195         VAProfile profile,
196         VAEntrypoint entrypoint,
197         AttribMap **attributeList) override;
198     virtual VAStatus CreateDecAttributes(
199         VAProfile profile,
200         VAEntrypoint entrypoint,
201         AttribMap **attributeList)               override;
202 
203     virtual VAStatus LoadHevcDecProfileEntrypoints() override;
204 
205     //!
206     //! \brief        Initialize HEVC low-power encode profiles, entrypoints and attributes
207     //!
208     //! \return VAStatus
209     //!     if call succeeds
210     //!
211     VAStatus LoadHevcEncLpProfileEntrypoints();
212 
213     //!
214     //! \brief      Query AVC ROI maximum number
215     //!
216     //! \param      [in] rcMode
217     //!     RC mode
218     //! \param      [in] isVdenc
219     //!     vdenc
220     //! \param      [in] maxNum
221     //!     Maximum number
222     //! \param      [in] isRoiInDeltaQP
223     //!     Is ROI in delta QP
224     //!
225     //! \return VAStatus
226     //!     if call succeeds
227     //!
228     VAStatus QueryAVCROIMaxNum(uint32_t rcMode, bool isVdenc, uint32_t *maxNum, bool *isRoiInDeltaQP) override;
229 };
230 #endif
231