xref: /aosp_15_r20/external/intel-media-driver/media_common/linux/common/codec/ddi_codec_def_specific.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2022, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file     ddi_codec_def_specific.h
24 //! \brief    libva codec interface head file
25 //!
26 
27 #ifndef __DDI_CODEC_DEF_SPECIFIC_H__
28 #define __DDI_CODEC_DEF_SPECIFIC_H__
29 
30 #include "media_libva_common_next.h"
31 
32 /* Number of forward references */
33 #define DDI_CODEC_NUM_FWD_REF         0
34 /* Number of backward references */
35 #define DDI_CODEC_NUM_BK_REF          0
36 /* Number of vp surface attributes */
37 #define DDI_CODEC_NUM_QUERY_ATTR_VP   9
38 
39 #define DDI_CODEC_BITSTREAM_BUFFER_INDEX_BITS 4  //the bitstream buffer index is 4 bits length
40 #define DDI_CODEC_MAX_BITSTREAM_BUFFER_INDEX  0xF  // the maximum bitstream buffer index is 0xF
41 #define DDI_CODEC_INVALID_BUFFER_INDEX        -1
42 #define DDI_CODEC_MIN_VALUE_OF_MAX_BS_SIZE    10240
43 
44 #define DDI_CODEC_FEI_MAX_INTERFACE_REVISION  1000
45 #define DDI_CODEC_FEI_CTB_CMD_SIZE_SKL        16
46 #define DDI_CODEC_FEI_CU_RECORD_SIZE_SKL_KBL  64
47 #define DDI_CODEC_STATS_MAX_NUM_PAST_REFS     1
48 #define DDI_CODEC_STATS_MAX_NUM_FUTURE_REFS   1
49 #define DDI_CODEC_STATS_MAX_NUM_OUTPUTS       3
50 #define DDI_CODEC_STATS_INTERLACED_SUPPORT    1
51 
52 #define DDI_CODEC_NUM_MAX_REF_FRAME           16
53 
54 #define DDI_CODEC_MAX_BITSTREAM_BUFFER        16
55 #define DDI_CODEC_MAX_BITSTREAM_BUFFER_MINUS1 (DDI_CODEC_MAX_BITSTREAM_BUFFER - 1)
56 #define DDI_CODEC_VP8_MAX_REF_FRAMES          5
57 #define DDI_CODEC_INVALID_FRAME_INDEX         0xffffffff
58 
59 #define DDI_CODEC_NUM_MACROBLOCKS_WIDTH(dwWidth)     ((dwWidth + (CODECHAL_MACROBLOCK_WIDTH - 1)) / CODECHAL_MACROBLOCK_WIDTH)
60 #define DDI_CODEC_NUM_MACROBLOCKS_HEIGHT(dwHeight)   ((dwHeight + (CODECHAL_MACROBLOCK_HEIGHT - 1)) / CODECHAL_MACROBLOCK_HEIGHT)
61 
62 typedef struct _DDI_CODEC_VC1BITPLANE_OBJECT
63 {
64     uint8_t       *pBitPlaneBase;
65     bool           bUsed;
66 } DDI_CODEC_VC1BITPLANE_OBJECT;
67 
68 typedef struct _DDI_CODEC_RENDER_TARGET_TABLE
69 {
70     int32_t                      iNumRenderTargets;
71     DDI_MEDIA_SURFACE           *pCurrentRT;           // raw input for encode
72     DDI_MEDIA_SURFACE           *pCurrentReconTarget;  // recon surface for encode
73     DDI_MEDIA_SURFACE           *pRT[DDI_MEDIA_MAX_SURFACE_NUMBER_CONTEXT];
74     uint8_t                      ucRTFlag[DDI_MEDIA_MAX_SURFACE_NUMBER_CONTEXT];
75 } DDI_CODEC_RENDER_TARGET_TABLE, *PDDI_CODEC_RENDER_TARGET_TABLE;
76 
77 typedef struct _DDI_CODEC_BITSTREAM_BUFFER_INFO
78 {
79     uint8_t            *pBaseAddress; // For JPEG it is a memory address when allocate slice data from CPU.
80     uint32_t            uiOffset;
81     uint32_t            uiLength;
82     VABufferID          vaBufferId;
83     bool                bRendered; // whether this slice data will be rendered.
84     PDDI_MEDIA_BUFFER   pMappedGPUBuffer; // the GPU mapping for this buffer.
85     bool                bIsUseExtBuf;
86     uint8_t            *pSliceBuf;
87 } DDI_CODEC_BITSTREAM_BUFFER_INFO;
88 
89 typedef struct _DDI_CODEC_BUFFER_PARAM_H264
90 {
91     // slice control buffer
92     VASliceParameterBufferH264                  *pVASliceParaBufH264;
93     VASliceParameterBufferBase                  *pVASliceParaBufH264Base;
94 
95     // one picture buffer
96     VAPictureParameterBufferH264                 PicParam264;
97 
98     // one IQ buffer
99     VAIQMatrixBufferH264                         IQm264;
100 } DDI_CODEC_BUFFER_PARAM_H264;
101 
102 typedef struct _DDI_CODEC_BUFFER_PARAM_MPEG2
103 {
104     // slice control buffer
105     VASliceParameterBufferMPEG2                  *pVASliceParaBufMPEG2;
106 
107     // one picture buffer
108     VAPictureParameterBufferMPEG2                 PicParamMPEG2;
109 
110     // one IQ buffer
111     VAIQMatrixBufferMPEG2                         IQmMPEG2;
112 } DDI_CODEC_BUFFER_PARAM_MPEG2;
113 
114 typedef struct _DDI_CODEC_BUFFER_PARAM_VC1
115 {
116     // slice control buffer
117     VASliceParameterBufferVC1                     *pVASliceParaBufVC1;
118 
119     // one picture buffer
120     VAPictureParameterBufferVC1                   PicParamVC1;
121     uint8_t                                      *pBitPlaneBuffer;
122     DDI_MEDIA_BUFFER                             *pVC1BitPlaneBuffObject[DDI_CODEC_MAX_BITSTREAM_BUFFER];
123     DDI_CODEC_VC1BITPLANE_OBJECT                  VC1BitPlane[DDI_CODEC_MAX_BITSTREAM_BUFFER];
124     uint32_t                                      dwVC1BitPlaneIndex;
125     MOS_RESOURCE                                  resBitPlaneBuffer;
126 } DDI_CODEC_BUFFER_PARAM_VC1;
127 
128 typedef struct _DDI_CODEC_BUFFER_PARAM_JPEG
129 {
130     // slice parameter buffer
131     VASliceParameterBufferJPEGBaseline                    *pVASliceParaBufJPEG;
132 
133     // picture parameter buffer
134     VAPictureParameterBufferJPEGBaseline                  PicParamJPEG;
135 
136     //IQ Matrix Buffer
137     VAIQMatrixBufferJPEGBaseline                          IQmJPEG;
138 } DDI_CODEC_BUFFER_PARAM_JPEG;
139 
140 typedef struct _DDI_CODEC_BUFFER_PARAM_VP8
141 {
142     // slice control buffer
143     VASliceParameterBufferVP8                   *pVASliceParaBufVP8;
144 
145     // one picture buffer
146     VAPictureParameterBufferVP8                  PicParamVP8;
147 
148     // one IQ buffer
149     VAIQMatrixBufferVP8                          IQmVP8;
150 
151     // Probability data
152     DDI_MEDIA_BUFFER                            *pVP8ProbabilityDataBuffObject;
153     MOS_RESOURCE                                 resProbabilityDataBuffer;
154     uint8_t                                     *pProbabilityDataBase;
155     VAProbabilityDataBufferVP8                   ProbabilityDataVP8;
156 
157     // Reference frames
158     DDI_MEDIA_SURFACE                           *pReferenceFrames[DDI_CODEC_VP8_MAX_REF_FRAMES];
159 } DDI_CODEC_BUFFER_PARAM_VP8;
160 
161 typedef struct _DDI_CODEC_BUFFER_PARAM_HEVC
162 {
163     // slice control buffer
164     VASliceParameterBufferHEVC                  *pVASliceParaBufHEVC;
165     VASliceParameterBufferBase                  *pVASliceParaBufBaseHEVC;
166     //slice control buffe for range extension
167     VASliceParameterBufferHEVCExtension          *pVASliceParaBufHEVCRext;
168 
169     // one picture buffer
170     VAPictureParameterBufferHEVC                 PicParamHEVC;
171 
172     //one picture buffer for range extension
173     VAPictureParameterBufferHEVCExtension        PicParamHEVCRext;
174 
175     // one IQ buffer
176     VAIQMatrixBufferHEVC                         IQmHEVC;
177 } DDI_CODEC_BUFFER_PARAM_HEVC;
178 
179 typedef struct _DDI_CODEC_BUFFER_PARAM_VP9
180 {
181     // one picture buffer
182     VADecPictureParameterBufferVP9               PicParamVP9;
183 
184     // slice control buffer: 8 * sizeof(VASegmentParameterVP9)
185     VASliceParameterBufferVP9                   *pVASliceParaBufVP9;
186 } DDI_CODEC_BUFFER_PARAM_VP9;
187 
188 typedef struct _DDI_CODEC_COM_BUFFER_MGR
189 {
190     // bitstream buffer
191     DDI_MEDIA_BUFFER                            *pBitStreamBuffObject[DDI_CODEC_MAX_BITSTREAM_BUFFER];
192     uint8_t                                     *pBitStreamBase[DDI_CODEC_MAX_BITSTREAM_BUFFER];
193     uint32_t                                     dwBitstreamIndex;   //indicating which bitstream buffer is used now
194     uint64_t                                     ui64BitstreamOrder; //save  bitstream buffer index used by previous 15 frames and current frame. the MSB is the oldest one, the LSB is current one.
195     MOS_RESOURCE                                 resBitstreamBuffer;
196     uint8_t                                     *pBitstreamBuffer;
197     DDI_CODEC_BITSTREAM_BUFFER_INFO             *pSliceData;
198     uint32_t                                     m_maxNumSliceData;
199     uint32_t                                     dwNumSliceData;
200     uint32_t                                     dwNumSliceControl;
201     uint32_t                                     dwMaxBsSize;
202 
203     uint32_t                                     dwSizeOfRenderedSliceData; // Size of all the rendered slice data buffer
204     uint32_t                                     dwNumOfRenderedSliceData; // how many slice data buffers will be rendered.
205     uint32_t                                     dwNumOfRenderedSlicePara; // how many slice parameters buffers will be rendered.
206     int32_t                                     *pNumOfRenderedSliceParaForOneBuffer; // how many slice headers in one slice parameter buffer.
207     int32_t                                     *pRenderedOrder; // a array to keep record the sequence when slice data rendered.
208     bool                                         bIsSliceOverSize;
209     //decode parameters
210     union
211     {
212         DDI_CODEC_BUFFER_PARAM_H264  Codec_Param_H264;
213         DDI_CODEC_BUFFER_PARAM_MPEG2 Codec_Param_MPEG2;
214         DDI_CODEC_BUFFER_PARAM_VC1   Codec_Param_VC1;
215         DDI_CODEC_BUFFER_PARAM_JPEG  Codec_Param_JPEG;
216         DDI_CODEC_BUFFER_PARAM_VP8   Codec_Param_VP8;
217         DDI_CODEC_BUFFER_PARAM_HEVC  Codec_Param_HEVC;
218         DDI_CODEC_BUFFER_PARAM_VP9   Codec_Param_VP9;
219     } Codec_Param;
220 
221     uint32_t                                     dwEncodeNumSliceControl;
222 
223     void                                        *pHDCP2ParameterBuffer;
224 
225     VACodedBufferSegment                        *pCodedBufferSegment; // For bitstream output
226     VAProcPipelineParameterBuffer                ProcPipelineParamBuffer;
227     VAProcFilterParameterBuffer                  ProcFilterParamBuffer;
228     VACodedBufferSegment                        *pCodedBufferSegmentForStatusReport; // for extended Status report such as long-term reference for VP8-F encode
229     void                                        *pCodecParamReserved;
230     void                                        *pCodecSlcParamReserved;
231 
232     // for External decode StreamOut Buffer
233     MOS_RESOURCE                                 resExternalStreamOutBuffer;
234 } DDI_CODEC_COM_BUFFER_MGR;
235 
236 #endif