OSDN Git Service

Make logging callbacks library-safe
[android-x86/hardware-intel-common-libva.git] / va / va_fei_h264.h
1 /*
2  * Copyright (c) 2007-2017 Intel Corporation. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 /**
26  * \file va_fei_h264.h
27  * \brief The FEI encoding H264 special API
28  */
29
30 #ifndef VA_FEI_H264_H
31 #define VA_FEI_H264_H
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #include <stdint.h>
38 #include "va_fei.h"
39
40 /** \brief FEI frame level control buffer for H.264 */
41 typedef struct _VAEncMiscParameterFEIFrameControlH264
42 {
43     uint32_t      function; /* one of the VAConfigAttribFEIFunctionType values */
44     /** \brief MB (16x16) control input buffer. It is valid only when (mb_input | mb_size_ctrl)
45      * is set to 1. The data in this buffer correspond to the input source. 16x16 MB is in raster scan order,
46      * each MB control data structure is defined by VAEncFEIMBControlH264.
47      * Buffer size shall not be less than the number of 16x16 blocks multiplied by
48      * sizeof(VAEncFEIMBControlH264).
49      * Note: if mb_qp is set, VAEncQPBufferH264 is expected.
50      */
51     VABufferID    mb_ctrl;
52     /** \brief distortion output of MB ENC or ENC_PAK.
53      * Each 16x16 block has one distortion data with VAEncFEIDistortionH264 layout
54      * Buffer size shall not be less than the number of 16x16 blocks multiplied by
55      * sizeof(VAEncFEIDistortionH264).
56      */
57     VABufferID    distortion;
58     /** \brief MVs data output of MB ENC.
59      * Each 16x16 block has one MVs data with layout VAMotionVector
60      * Buffer size shall not be less than the number of 16x16 blocks multiplied by
61      * sizeof(VAMotionVector) * 16.
62      */
63     VABufferID    mv_data;
64     /** \brief MBCode data output of MB ENC.
65      * Each 16x16 block has one MB Code data with layout VAEncFEIMBCodeH264
66      * Buffer size shall not be less than the number of 16x16 blocks multiplied by
67      * sizeof(VAEncFEIMBCodeH264).
68      */
69     VABufferID    mb_code_data;
70     /** \brief QP input buffer with layout VAEncQPBufferH264. It is valid only when mb_qp is set to 1.
71      * The data in this buffer correspond to the input source.
72      * One QP per 16x16 block in raster scan order, each QP is a signed char (8-bit) value.
73      **/
74     VABufferID    qp;
75     /** \brief MV predictor. It is valid only when mv_predictor_enable is set to 1.
76      * Each 16x16 block has one or more pair of motion vectors and the corresponding
77      * reference indexes as defined by VAEncFEIMVPredictorH264. 16x16 block is in raster scan order.
78      * Buffer size shall not be less than the number of 16x16 blocks multiplied by
79      * sizeof(VAEncFEIMVPredictorH264). */
80     VABufferID    mv_predictor;
81
82     /** \brief number of MV predictors. It must not be greater than maximum supported MV predictor. */
83     uint32_t      num_mv_predictors_l0      : 16;
84     uint32_t      num_mv_predictors_l1      : 16;
85
86     /** \brief motion search method definition
87      * 0: default value, diamond search
88      * 1: full search
89      * 2: diamond search
90      **/
91     uint32_t      search_path               : 8;
92     /** \brief maximum number of Search Units, valid range is [1, 63] */
93     uint32_t      len_sp                    : 8;
94     uint32_t      reserved0                     : 16;
95
96     uint32_t      sub_mb_part_mask          : 7;
97     uint32_t      intra_part_mask           : 5;
98     uint32_t      multi_pred_l0             : 1;
99     uint32_t      multi_pred_l1             : 1;
100     uint32_t      sub_pel_mode              : 2;
101     uint32_t      inter_sad                 : 2;
102     uint32_t      intra_sad                 : 2;
103     uint32_t      distortion_type           : 1;
104     uint32_t      repartition_check_enable  : 1;
105     uint32_t      adaptive_search           : 1;
106     uint32_t      mv_predictor_enable       : 1;
107     uint32_t      mb_qp                     : 1;
108     uint32_t      mb_input                  : 1;
109     uint32_t      mb_size_ctrl              : 1;
110     uint32_t      colocated_mb_distortion   : 1;
111     uint32_t      reserved1                     : 4;
112
113     /** \brief motion search window(ref_width * ref_height) */
114     uint32_t      ref_width                 : 8;
115     uint32_t      ref_height                : 8;
116     /** \brief predefined motion search windows. If selected, len_sp, window(ref_width * ref_eight)
117      * and search_path setting are ignored.
118      * 0: not use predefined search window
119      * 1: Tiny, len_sp=4, 24x24 window and diamond search
120      * 2: Small, len_sp=9, 28x28 window and diamond search
121      * 3: Diamond, len_sp=16, 48x40 window and diamond search
122      * 4: Large Diamond, len_sp=32, 48x40 window and diamond search
123      * 5: Exhaustive, len_sp=48, 48x40 window and full search
124      * 6: Extend Diamond, len_sp=16, 64x40 window and diamond search
125      * 7: Extend Large Diamond, len_sp=32, 64x40 window and diamond search
126      * 8: Extend Exhaustive, len_sp=48, 64x40 window and full search
127      **/
128     uint32_t      search_window             : 4;
129     uint32_t      reserved2                 : 12;
130
131     /** \brief max frame size control with multi passes QP setting */
132     uint32_t      max_frame_size;
133     /** \brief number of passes, every pass has different QP */
134     uint32_t      num_passes;
135     /** \brief delta QP list for every pass */
136     uint8_t       *delta_qp;
137     uint32_t      reserved3[2];
138 } VAEncMiscParameterFEIFrameControlH264;
139
140 /** \brief FEI MB level control data structure */
141 typedef struct _VAEncFEIMBControlH264
142 {
143     /** \brief when set, correposndent MB is coded as intra */
144     uint32_t force_to_intra                : 1;
145     /** \brief when set, correposndent MB is coded as skip */
146     uint32_t force_to_skip                 : 1;
147     uint32_t force_to_nonskip              : 1;
148     uint32_t enable_direct_bias_adjustment : 1;
149     uint32_t enable_motion_bias_adjustment : 1;
150     uint32_t ext_mv_cost_scaling_factor    : 3;
151     uint32_t reserved0                     : 24;
152
153     uint32_t reserved1;
154
155     uint32_t reserved2;
156
157     /** \brief when mb_size_ctrl is set, size here is used to budget accumulatively. Set to 0xFF if don't care. */
158     uint32_t reserved3                     : 16;
159     uint32_t target_size_in_word           : 8;
160     uint32_t max_size_in_word              : 8;
161 } VAEncFEIMBControlH264;
162
163
164 /** \brief Application can use this definition as reference to allocate the buffer
165  * based on MaxNumPredictor returned from attribute VAConfigAttribFEIMVPredictors query.
166  **/
167 typedef struct _VAEncFEIMVPredictorH264
168 {
169     /** \brief Reference index corresponding to the entry of RefPicList0 & RefPicList1 in VAEncSliceParameterBufferH264.
170      * Note that RefPicList0 & RefPicList1 needs to be the same for all slices.
171      * ref_idx_l0_x : index to RefPicList0; ref_idx_l1_x : index to RefPicList1; x : 0 - MaxNumPredictor.
172      **/
173     struct {
174         uint8_t   ref_idx_l0    : 4;
175         uint8_t   ref_idx_l1    : 4;
176     } ref_idx[4]; /* index is predictor number */
177     uint32_t reserved;
178     /** \brief MV. MaxNumPredictor must be the returned value from attribute VAConfigAttribFEIMVPredictors query.
179      * Even application doesn't use the maximum predictors, the VAFEIMVPredictorH264 structure size
180      * has to be defined as maximum so each MB can be at a fixed location.
181      * Note that 0x8000 must be used for correspondent intra block.
182      **/
183     VAMotionVector mv[4]; /* MaxNumPredictor is 4 */
184 } VAEncFEIMVPredictorH264;
185
186 /** \brief FEI output */
187 /**
188  * Motion vector output is per 4x4 block. For each 4x4 block there is a pair of MVs
189  * for RefPicList0 and RefPicList1 and each MV is 4 bytes including horizontal and vertical directions.
190  * Depending on Subblock partition, for the shape that is not 4x4, the MV is replicated
191  * so each 4x4 block has a pair of MVs. The 16x16 block has 32 MVs (128 bytes).
192  * 0x8000 is used for correspondent intra block. The 16x16 block is in raster scan order,
193  * within the 16x16 block, each 4x4 block MV is ordered as below in memory.
194  * The buffer size shall be greater than or equal to the number of 16x16 blocks multiplied by 128 bytes.
195  * Note that, when separate ENC and PAK is enabled, the exact layout of this buffer is needed for PAK input.
196  * App can reuse this buffer, or copy to a different buffer as PAK input.
197  * Layout is defined as Generic motion vector data structure VAMotionVector
198  *                      16x16 Block
199  *        -----------------------------------------
200  *        |    1    |    2    |    5    |    6    |
201  *        -----------------------------------------
202  *        |    3    |    4    |    7    |    8    |
203  *        -----------------------------------------
204  *        |    9    |    10   |    13   |    14   |
205  *        -----------------------------------------
206  *        |    11   |    12   |    15   |    16   |
207  *        -----------------------------------------
208  **/
209
210 /** \brief VAEncFEIMBCodeH264 defines the data structure for VAEncFEIMBCodeBufferType per 16x16 MB block.
211  * it is output buffer of ENC and ENC_PAK modes, it's also input buffer of PAK mode.
212  * The 16x16 block is in raster scan order. Buffer size shall not be less than the number of 16x16 blocks
213  * multiplied by sizeof(VAEncFEIMBCodeH264). Note that, when separate ENC and PAK is enabled,
214  * the exact layout of this buffer is needed for PAK input. App can reuse this buffer,
215  * or copy to a different buffer as PAK input, reserved elements must not be modified when used as PAK input.
216  **/
217 typedef struct _VAEncFEIMBCodeH264
218 {
219     //DWORD  0~2
220     uint32_t    reserved0[3];
221
222     //DWORD  3
223     uint32_t    inter_mb_mode            : 2;
224     uint32_t    mb_skip_flag             : 1;
225     uint32_t    reserved1                : 1;
226     uint32_t    intra_mb_mode            : 2;
227     uint32_t    reserved2                : 1;
228     uint32_t    field_mb_polarity_flag   : 1;
229     uint32_t    mb_type                  : 5;
230     uint32_t    intra_mb_flag            : 1;
231     uint32_t    field_mb_flag            : 1;
232     uint32_t    transform8x8_flag        : 1;
233     uint32_t    reserved3                : 1;
234     uint32_t    dc_block_coded_cr_flag   : 1;
235     uint32_t    dc_block_coded_cb_flag   : 1;
236     uint32_t    dc_block_coded_y_flag    : 1;
237     uint32_t    reserved4                : 12;
238
239     //DWORD 4
240     uint32_t    horz_origin              : 8;
241     uint32_t    vert_origin              : 8;
242     uint32_t    cbp_y                    : 16;
243
244     //DWORD 5
245     uint32_t    cbp_cb                   : 16;
246     uint32_t    cbp_cr                   : 16;
247
248     //DWORD 6
249     uint32_t    qp_prime_y               : 8;
250     uint32_t    reserved5                : 17;
251     uint32_t    mb_skip_conv_disable     : 1;
252     uint32_t    is_last_mb               : 1;
253     uint32_t    enable_coefficient_clamp : 1;
254     uint32_t    direct8x8_pattern        : 4;
255
256     //DWORD 7 8 and 9
257     union
258     {
259         /* Intra MBs */
260         struct
261         {
262             uint32_t   luma_intra_pred_modes0 : 16;
263             uint32_t   luma_intra_pred_modes1 : 16;
264
265             uint32_t   luma_intra_pred_modes2 : 16;
266             uint32_t   luma_intra_pred_modes3 : 16;
267
268             uint32_t   chroma_intra_pred_mode : 2;
269             uint32_t   intra_pred_avail_flag  : 5;
270             uint32_t   intra_pred_avail_flagF : 1;
271             uint32_t   reserved6              : 24;
272         } intra_mb;
273
274         /* Inter MBs */
275         struct
276         {
277             uint32_t   sub_mb_shapes          : 8;
278             uint32_t   sub_mb_pred_modes      : 8;
279             uint32_t   reserved7              : 16;
280
281             uint32_t   ref_idx_l0_0           : 8;
282             uint32_t   ref_idx_l0_1           : 8;
283             uint32_t   ref_idx_l0_2           : 8;
284             uint32_t   ref_idx_l0_3           : 8;
285
286             uint32_t   ref_idx_l1_0           : 8;
287             uint32_t   ref_idx_l1_1           : 8;
288             uint32_t   ref_idx_l1_2           : 8;
289             uint32_t   ref_idx_l1_3           : 8;
290         } inter_mb;
291     } mb_mode;
292
293     //DWORD 10
294     uint32_t   reserved8                 : 16;
295     uint32_t   target_size_in_word       : 8;
296     uint32_t   max_size_in_word          : 8;
297
298     //DWORD 11~14
299     uint32_t   reserved9[4];
300
301     //DWORD 15
302     uint32_t   reserved10;
303 } VAEncFEIMBCodeH264;        // 64 bytes
304
305 /** \brief VAEncFEIDistortionH264 defines the data structure for VAEncFEIDistortionBufferType per 16x16 MB block.
306  * It is output buffer of ENC and ENC_PAK modes, The 16x16 block is in raster scan order.
307  * Buffer size shall not be less than the number of 16x16 blocks multiple by sizeof(VAEncFEIDistortionH264).
308  **/
309 typedef struct _VAEncFEIDistortionH264 {
310     /** \brief Inter-prediction-distortion associated with motion vector i (co-located with subblock_4x4_i).
311      * Its meaning is determined by sub-shape. It must be zero if the corresponding sub-shape is not chosen.
312      **/
313     uint16_t    inter_distortion[16];
314     uint32_t    best_inter_distortion     : 16;
315     uint32_t    best_intra_distortion     : 16;
316     uint32_t    colocated_mb_distortion   : 16;
317     uint32_t    reserved0                 : 16;
318     uint32_t    reserved1[2];
319 } VAEncFEIDistortionH264;    // 48 bytes
320
321 #ifdef __cplusplus
322 }
323 #endif
324
325 #endif /* VA_FEI_H264_H */