1 /*
2 * Copyright (c) 2017, 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     codec_def_decode_hevc.h
24 //! \brief    Defines decode HEVC types and macros shared by CodecHal, MHW, and DDI layer
25 //! \details  Applies to HEVC decode only. Should not contain any DDI specific code.
26 //!
27 #ifndef __CODEC_DEF_DECODE_HEVC_H__
28 #define __CODEC_DEF_DECODE_HEVC_H__
29 
30 #include "codec_def_common_hevc.h"
31 
32 #define CODEC_NUM_REF_HEVC_MV_BUFFERS       CODEC_MAX_NUM_REF_FRAME_HEVC
33 #define CODEC_NUM_HEVC_MV_BUFFERS           (CODEC_NUM_REF_HEVC_MV_BUFFERS + 1)
34 #define CODEC_NUM_HEVC_INITIAL_MV_BUFFERS   6
35 #define HEVC_NUM_MAX_TILE_ROW               22
36 #define HEVC_NUM_MAX_TILE_COLUMN            20
37 #define CODECHAL_HEVC_MAX_NUM_SLICES_LVL_6  600
38 #define CODECHAL_HEVC_MAX_NUM_SLICES_LVL_5  200
39 #define CODECHAL_HEVC_NUM_DMEM_BUFFERS      32
40 
41 #define CODEC_HEVC_NUM_SECOND_BB            32
42 
43 #define CODECHAL_HEVC_MIN_LCU               16
44 #define CODECHAL_HEVC_MAX_DIM_FOR_MIN_LCU   4222
45 
46 const uint8_t CODECHAL_DECODE_HEVC_Qmatrix_Scan_4x4[16] = { 0, 4, 1, 8, 5, 2, 12, 9, 6, 3, 13, 10, 7, 14, 11, 15 };
47 const uint8_t CODECHAL_DECODE_HEVC_Qmatrix_Scan_8x8[64] =
48 { 0, 8, 1, 16, 9, 2, 24, 17, 10, 3, 32, 25, 18, 11, 4, 40,
49 33, 26, 19, 12, 5, 48, 41, 34, 27, 20, 13, 6, 56, 49, 42, 35,
50 28, 21, 14, 7, 57, 50, 43, 36, 29, 22, 15, 58, 51, 44, 37, 30,
51 23, 59, 52, 45, 38, 31, 60, 53, 46, 39, 61, 54, 47, 62, 55, 63 };
52 const uint8_t CODECHAL_DECODE_HEVC_Default_4x4[16] = { 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 };
53 const uint8_t CODECHAL_DECODE_HEVC_Default_8x8_Intra[64] =
54 { 16, 16, 16, 16, 17, 18, 21, 24, 16, 16, 16, 16, 17, 19, 22, 25,
55 16, 16, 17, 18, 20, 22, 25, 29, 16, 16, 18, 21, 24, 27, 31, 36,
56 17, 17, 20, 24, 30, 35, 41, 47, 18, 19, 22, 27, 35, 44, 54, 65,
57 21, 22, 25, 31, 41, 54, 70, 88, 24, 25, 29, 36, 47, 65, 88, 115 };
58 const uint8_t CODECHAL_DECODE_HEVC_Default_8x8_Inter[64] =
59 { 16, 16, 16, 16, 17, 18, 20, 24, 16, 16, 16, 17, 18, 20, 24, 25,
60 16, 16, 17, 18, 20, 24, 25, 28, 16, 17, 18, 20, 24, 25, 28, 33,
61 17, 18, 20, 24, 25, 28, 33, 41, 18, 20, 24, 25, 28, 33, 41, 54,
62 20, 24, 25, 28, 33, 41, 54, 71, 24, 25, 28, 33, 41, 54, 71, 91 };
63 
64 enum
65 {
66     decodeHevcBSlice        = 0,
67     decodeHevcPSlice        = 1,
68     decodeHevcISlice        = 2,
69     decodeHevcNumSliceTypes = 3
70 };
71 
72 /*! \brief Picture-level parameters of a compressed picture for HEVC decoding.
73  *
74  *   Note 1: Application only pass in the first num_tile_columns_minus1 tile column widths and first num_tile_rows_minus1 tile row heights. The last width and height need to be calculated by driver from the picture dimension. Values used for data type alignement. Their values should be set to 0, and can be ignored by decoder.
75  *   Note 2: HEVC host decoder should discard any NAL units with nal_unit_type in the range of [10 – 15, 22 – 63].
76  *   Note 3: When tiles_enabled_flag equals 1 and uniform_spacing_flag takes value 1, driver may ignore the values passed in column_width_minus1[] and raw_height_minus1[]. Instead driver should generate and populate these tile dimension values based on picture resolution and num_tile_columns_minus1, num_tile_rows_minus1. It can be referred to formula (6-3) and (6-4) in HEVC spec.
77  */
78 typedef struct _CODEC_HEVC_PIC_PARAMS
79 {
80     /*! \brief Width of decoded pictures in units of minimum luma coding block size.
81     *
82     *   The decoded picture width in units of luma samples equals (PicWidthInMinCbsY) * (1 << (log2_min_coding_block_size_minus3 + 3)).
83     */
84     uint16_t                      PicWidthInMinCbsY;
85     /*! \brief Height of decoded pictures in units of minimum luma coding block size.
86     *
87     *   The decoded picture height in units of luma samples equals (PicHeightInMinCbsY) * (1 << (log2_min_coding_block_size_minus3 + 3)).
88     */
89     uint16_t                      PicHeightInMinCbsY;
90 
91     union
92     {
93         struct
94         {
95             uint16_t              chroma_format_idc                   : 2;    //!< Same as HEVC syntax element
96             uint16_t              separate_colour_plane_flag          : 1;    //!< Same as HEVC syntax element
97             uint16_t              bit_depth_luma_minus8               : 3;    //!< Same as HEVC syntax element
98             uint16_t              bit_depth_chroma_minus8             : 3;    //!< Same as HEVC syntax element
99             uint16_t              log2_max_pic_order_cnt_lsb_minus4   : 4;    //!< Same as HEVC syntax element
100             /*! \brief Indicates that no picture reordering is used in the coded video sequence.
101             *
102             *   If equal to 1, the maximum allowed number of pictures preceding any picture in decoding order and succeeding that picture in output order is equal to 0. When NoPicReorderingFlag equal to 0, picture reordering may be used in the coded video sequence. This flag does not affect the decoding process.
103             *   Note: NoPicReorderingFlag may be set to 1 by the host software decoder when sps_max_num_reorder_pics is equal to 0. However, there is no requirement that NoPicReorderingFlag must be derived from sps_max_num_reorder_pics.
104             */
105             uint16_t              NoPicReorderingFlag                 : 1;
106             /*! \brief Indicates that B slices are not used in the coded video sequence.
107             *
108             *   This flag does not affect the decoding process.
109             *   Note: This flag does not correspond to any indication provided in the HEVC bitstream itself. Thus, a host software decoder would need some external information (e.g. as determined at the application level) to be able to set this flag to 1. In the absence of any such available indication, the host software decoder must set this flag to 0.
110             */
111             uint16_t              NoBiPredFlag                        : 1;
112             uint16_t              ReservedBits1                       : 1;    //!< Value is used for alignemnt and has no meaning, set to 0.
113         };
114 
115         uint16_t                  wFormatAndSequenceInfoFlags;
116     };
117 
118     /*! \brief Uncompressed destination surface of the frame for the current decoded picture.
119     *
120     *   The long_term_ref_flag has no meaning. The valid value range for Curr.FrameIdx is [0..126]. Value 127 or 0x7F can be treated as an invalid surface index.
121     */
122     CODEC_PICTURE               CurrPic;
123 
124     /*! \brief Number of reference frames in the DPB buffer.
125     *
126     *   Host decoder should set this value to be sps_max_dec_pic_buffering_minus1 of the temporal layer where the current decoding frame is of. The value should be between 0 and 15, inclusive.
127     */
128     uint8_t                       sps_max_dec_pic_buffering_minus1;
129     uint8_t                       log2_min_luma_coding_block_size_minus3;         //!< Same as HEVC syntax element
130     uint8_t                       log2_diff_max_min_luma_coding_block_size;       //!< Same as HEVC syntax element
131     uint8_t                       log2_min_transform_block_size_minus2;           //!< Same as HEVC syntax element
132     uint8_t                       log2_diff_max_min_transform_block_size;         //!< Same as HEVC syntax element
133     uint8_t                       max_transform_hierarchy_depth_inter;            //!< Same as HEVC syntax element
134     uint8_t                       max_transform_hierarchy_depth_intra;            //!< Same as HEVC syntax element
135     uint8_t                       num_short_term_ref_pic_sets;                    //!< Same as HEVC syntax element
136     uint8_t                       num_long_term_ref_pic_sps;                      //!< Same as HEVC syntax element
137     /*! \brief Same as HEVC syntax element.
138     *
139     *   When long slice control data format is taken, hardware decoder should take values from num_ref_idx_l0_active_minus1 and num_ref_idx_l1_active_minus1 from slice control data structure.
140     */
141     uint8_t                       num_ref_idx_l0_default_active_minus1;
142     /*! \brief Same as HEVC syntax element.
143     *
144     *   When long slice control data format is taken, hardware decoder should take values from num_ref_idx_l0_active_minus1 and num_ref_idx_l1_active_minus1 from slice control data structure.
145     */
146     uint8_t                       num_ref_idx_l1_default_active_minus1;
147     char                          init_qp_minus26;                                //!< Same as HEVC syntax element
148     /*! \brief Decoder may ignore this value.
149     *
150     *   This is an redundant parameter which serves as same purpose as wNumBitsForShortTermRPSInSlice.
151     */
152     uint8_t                       ucNumDeltaPocsOfRefRpsIdx;
153     /*! \brief Bit count in the bit stream for parsing short_term_ref_pic_set in slice segment header.
154     *
155     *   If short_term_ref_pic_set_sps_flag takes value 1, wNumBitsForShortTermRPSInSlice should be  0. The bit count value is calculated when emulation prevention bytes are removed from raw elementary bit stream.
156     */
157     uint16_t                      wNumBitsForShortTermRPSInSlice;
158     uint16_t                      ReservedBits2;                                  //!< Value is used for alignemnt and has no meaning, set to 0.
159 
160     union
161     {
162         struct
163         {
164             uint32_t              scaling_list_enabled_flag                    : 1;   //!< Same as HEVC syntax element
165             uint32_t              amp_enabled_flag                             : 1;   //!< Same as HEVC syntax element
166             uint32_t              sample_adaptive_offset_enabled_flag          : 1;   //!< Same as HEVC syntax element
167             uint32_t              pcm_enabled_flag                             : 1;   //!< Same as HEVC syntax element
168             uint32_t              pcm_sample_bit_depth_luma_minus1             : 4;   //!< Same as HEVC syntax element
169             uint32_t              pcm_sample_bit_depth_chroma_minus1           : 4;   //!< Same as HEVC syntax element
170             uint32_t              log2_min_pcm_luma_coding_block_size_minus3   : 2;   //!< Same as HEVC syntax element
171             uint32_t              log2_diff_max_min_pcm_luma_coding_block_size : 2;   //!< Same as HEVC syntax element
172             uint32_t              pcm_loop_filter_disabled_flag                : 1;   //!< Same as HEVC syntax element
173             uint32_t              long_term_ref_pics_present_flag              : 1;   //!< Same as HEVC syntax element
174             uint32_t              sps_temporal_mvp_enabled_flag                : 1;   //!< Same as HEVC syntax element
175             uint32_t              strong_intra_smoothing_enabled_flag          : 1;   //!< Same as HEVC syntax element
176             uint32_t              dependent_slice_segments_enabled_flag        : 1;   //!< Same as HEVC syntax element
177             uint32_t              output_flag_present_flag                     : 1;   //!< Same as HEVC syntax element
178             uint32_t              num_extra_slice_header_bits                  : 3;   //!< Same as HEVC syntax element
179             uint32_t              sign_data_hiding_enabled_flag                : 1;   //!< Same as HEVC syntax element
180             uint32_t              cabac_init_present_flag                      : 1;   //!< Same as HEVC syntax element
181             uint32_t              ReservedBits3                                : 5;   //!< Value is used for alignemnt and has no meaning, set to 0.
182        };
183 
184         uint32_t                  dwCodingParamToolFlags;
185     };
186 
187     union
188     {
189         struct
190         {
191             uint32_t              constrained_intra_pred_flag                 : 1;    //!< Same as HEVC syntax element
192             uint32_t              transform_skip_enabled_flag                 : 1;    //!< Same as HEVC syntax element
193             uint32_t              cu_qp_delta_enabled_flag                    : 1;    //!< Same as HEVC syntax element
194             uint32_t              pps_slice_chroma_qp_offsets_present_flag    : 1;    //!< Same as HEVC syntax element
195             uint32_t              weighted_pred_flag                          : 1;    //!< Same as HEVC syntax element
196             uint32_t              weighted_bipred_flag                        : 1;    //!< Same as HEVC syntax element
197             uint32_t              transquant_bypass_enabled_flag              : 1;    //!< Same as HEVC syntax element
198             uint32_t              tiles_enabled_flag                          : 1;    //!< Same as HEVC syntax element
199             uint32_t              entropy_coding_sync_enabled_flag            : 1;    //!< Same as HEVC syntax element
200             uint32_t              uniform_spacing_flag                        : 1;    //!< Same as HEVC syntax element
201             uint32_t              loop_filter_across_tiles_enabled_flag       : 1;    //!< Same as HEVC syntax element
202             uint32_t              pps_loop_filter_across_slices_enabled_flag  : 1;    //!< Same as HEVC syntax element
203             uint32_t              deblocking_filter_override_enabled_flag     : 1;    //!< Same as HEVC syntax element
204             uint32_t              pps_deblocking_filter_disabled_flag         : 1;    //!< Same as HEVC syntax element
205             /*! \brief Same as HEVC syntax element.
206             *
207             *   Host decoder should set the value properly based on syntax element restricted_ref_pic_lists_flag. If restricted_ref_pic_lists_flag equals 0, lists_modification_present_flag should be set to 1.
208             */
209             uint32_t              lists_modification_present_flag             : 1;
210             uint32_t              slice_segment_header_extension_present_flag : 1;    //!< Same as HEVC syntax element
211             /*! \brief Indicates whether the current picture is an IRAP picture.
212             *
213             *   This flag shall be equal to 1 when the current picture is an IRAP picture and shall be equal to 0 when the current picture is not an IRAP picture.
214             */
215             uint32_t              IrapPicFlag : 1;
216             /*! \brief Indicates whether the current picture is an IDR picture.
217             *
218             *   This flag shall be equal to 1 when the current picture is an IDR picture and shall be equal to 0 when the current picture is not an IDR picture.
219             */
220             uint32_t              IdrPicFlag : 1;
221             /*! \brief Takes value 1 when all the slices are intra slices, 0 otherwise.
222             */
223             uint32_t              IntraPicFlag                                : 1;
224             /*! \brief CRC values are requested if set to 1.
225             */
226             uint32_t              RequestCRC                                  : 1;
227             /*! \brief Histogram array is requested if set to 1.
228             *
229             *   If set, SFC should be enabled to generate the histogram array per channel. If other operations by SFC are required such as scaling, the histogram is generated against the final pixel buffer after the operation is performed.
230             */
231             uint32_t              RequestHistogram                            : 1;
232             uint32_t              ReservedBits4                               : 11;   //!< Value is used for alignemnt and has no meaning, set to 0.
233         };
234 
235         uint32_t                  dwCodingSettingPicturePropertyFlags;
236     };
237 
238     char                          pps_cb_qp_offset;                       //!< Same as HEVC syntax element
239     char                          pps_cr_qp_offset;                       //!< Same as HEVC syntax element
240     uint8_t                       num_tile_columns_minus1;                //!< Same as HEVC syntax element
241     uint8_t                       num_tile_rows_minus1;                   //!< Same as HEVC syntax element
242     uint16_t                      column_width_minus1[19];                //!< Same as HEVC syntax element
243     uint16_t                      row_height_minus1[21];                  //!< Same as HEVC syntax element
244     uint8_t                       diff_cu_qp_delta_depth;                 //!< Same as HEVC syntax element
245     char                          pps_beta_offset_div2;                   //!< Same as HEVC syntax element
246     char                          pps_tc_offset_div2;                     //!< Same as HEVC syntax element
247     uint8_t                       log2_parallel_merge_level_minus2;       //!< Same as HEVC syntax element
248 
249     /*! \brief Picture order count value for the current picture.
250     *
251     *   Value range is -2^31 to 2^31-1, inclusive.
252     */
253     int32_t                       CurrPicOrderCntVal;
254     /*! \brief FrameIdx for each entry specifies the surface index for all pictures that are or will be referred to by the current or future pictures.
255     *
256     *   The valid entries are indexed from 0 to 126, inclusive. The PicFlags of non-valid entries (including the picture of the entry which is not referred by current picture or future pictures) should take value PICTURE_INVALID. A PicFlags setting of PICTURE_LONG_TERM_REFERENCE indicates if the picture is a long term reference or not.
257     *   NOTE: for interlace (field) pictures, the FrameIdx field of two RefFrameList entries may have same value and point to same reference surface. And in this case, application should allocate buffer size with double picture height to hold the whole picture.
258     */
259     CODEC_PICTURE                 RefFrameList[15];
260     /*! \brief Picture order count value for each of the reference pictures in the DPB buffer surface, corresponding to the entries of RefFrameList[15].
261     */
262     int32_t                       PicOrderCntValList[15];
263     /*! \brief Contain the indices to the RefFrameList[] used in inter predection.
264     *
265     *   The indices to the RefFrameList[] indicate all the reference pictures that may be used in inter prediction of the current picture and that may be used in inter prediction of one or more of the pictures following the current picture in decoding order.
266     *   When an entry in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[] is not valid, it shall be set to 0xff. Invalid entries shall not be present between valid entries in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[]. Valid entries in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[] shall have values in the range of 0 to 7, inclusive, and each corresponding entry in RefFrameList[] referred to by a valid entry in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[] shall not have PicFlags equal to PICTURE_INVALID. Any entry in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[] that is not equal to 0xFF shall not be equal to the value of any other entry in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] or RefPicSetLtCurr[].
267     */
268     uint8_t                       RefPicSetStCurrBefore[8];
269     /*! \brief Contain the indices to the RefFrameList[] used in inter predection.
270     *
271     *   The indices to the RefFrameList[] indicate all the reference pictures that may be used in inter prediction of the current picture and that may be used in inter prediction of one or more of the pictures following the current picture in decoding order.
272     *   When an entry in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[] is not valid, it shall be set to 0xff. Invalid entries shall not be present between valid entries in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[]. Valid entries in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[] shall have values in the range of 0 to 7, inclusive, and each corresponding entry in RefFrameList[] referred to by a valid entry in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[] shall not have PicFlags equal to PICTURE_INVALID. Any entry in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[] that is not equal to 0xFF shall not be equal to the value of any other entry in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] or RefPicSetLtCurr[].
273     */
274     uint8_t                       RefPicSetStCurrAfter[8];
275     /*! \brief Contain the indices to the RefFrameList[] used in inter predection.
276     *
277     *   The indices to the RefFrameList[] indicate all the reference pictures that may be used in inter prediction of the current picture and that may be used in inter prediction of one or more of the pictures following the current picture in decoding order.
278     *   When an entry in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[] is not valid, it shall be set to 0xff. Invalid entries shall not be present between valid entries in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[]. Valid entries in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[] shall have values in the range of 0 to 7, inclusive, and each corresponding entry in RefFrameList[] referred to by a valid entry in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[] shall not have PicFlags equal to PICTURE_INVALID. Any entry in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] and RefPicSetLtCurr[] that is not equal to 0xFF shall not be equal to the value of any other entry in RefPicSetStCurrBefore[], RefPicSetStCurrAfter[] or RefPicSetLtCurr[].
279     */
280     uint8_t                       RefPicSetLtCurr[8];
281     /*! \brief Is a 16 entry array indicating whether or not a picture is a field picture.
282     *
283     *   Each bit of the low 15 bits indicats if the associated picture in DPB is a field picture or not. Specifically, if ((RefFieldPicFlag >> i) & 0x01) > 0, then the referencepicture specified by RefFrameList[i] is a field picture. Otherwise, it is frame picture. For field picture, coresponding bit of RefBottomFieldFlag indicates the field polarity. The MSB, (RefFieldPicFlag >> 15) & 0x01, indicates the field or frame status of current decoded picture, CurrPic.
284     */
285     uint16_t                      RefFieldPicFlag;
286     /*! \brief Is a 16 entry array indicating the polarity of a picture.
287     *
288     *   Each bit of the low 15 bits indicats the polarity of the associated reference field picture. If ((RefBottomFieldFlag >> i) & 0x01) > 0, then the reference picture  takes odd lines in the surface specified by RefFrameList[i]. And ((RefBottomFieldFlag >> i) & 0x01) = 0 indicates the reference picture takes even lines. The MSB, ((RefBottomFieldFlag >> i) & 0x01), indicates the polarity of the current decoded picture, CurrPic.
289     */
290     uint16_t                      RefBottomFieldFlag;
291     /*! \brief Arbitrary number set by the host decoder to use as a tag in the status report feedback data.
292     *
293     *   The value should not equal 0, and should be different in each call to Execute.
294     */
295     uint32_t                      StatusReportFeedbackNumber;
296     uint32_t                      dwLastSliceEndPos;
297 
298     uint16_t                      TotalNumEntryPointOffsets;  //!< Total entrypoint offset in subset buffer
299 } CODEC_HEVC_PIC_PARAMS, *PCODEC_HEVC_PIC_PARAMS;
300 
301 /*! \brief Slice-level parameters of a compressed picture for HEVC decoding.
302 *
303 *   The slice control buffer is accompanied by a raw bitstream data buffer. The total quantity of data in the bitstream buffer (and the amount of data reported by the host decoder) shall be an integer multiple of 128 bytes.
304 */
305 typedef struct _CODEC_HEVC_SLICE_PARAMS
306 {
307     /*! \brief Number of bytes in the bitstream data buffer that are associated with this slice control data structure.
308     *
309     *   Starting with the byte at the offset given in slice_data_offset. The bitstream data buffer shall not contain additional byte stream NAL units in the bytes following BSNALunitDataLocation up to the location slice_data_offset + slice_data_size. If slice_data_offset + slice_data_size exceeds the boundary of current bitstream data buffer, the excess slice bytes should continue from the first byte of next bitstream data buffer.
310     */
311     uint32_t                slice_data_size;
312     /*! \brief This member locates the NAL unit with nal_unit_type equal to 1 .. 8 for the current slice.
313     *
314     *   At least one bit stream data buffer should be present which is associated with the slice control data buffer. If necessary, multiple bit stream data buffers are allowed, but not suggested. The size of the data in the bitstream data buffer (and the amount of data reported by the host decoder) shall be an integer multiple of 128 bytes. When  the end of the slice data is not an even multiple of 128 bytes, the decoder should pad the end of the buffer with zeroes.  When more than one bitstream data buffers are present, these data buffers should be in sequential order. They should be treated as if concatenated linearly with no space in between.  The value of slice_data_offset is the byte offset, from the start of the first bitstream data buffer, of the first byte of the start code prefix in the byte stream NAL unit that contains the NAL unit with nal_unit_type equal to 1 .. 8. The current slice is the slice associated with this slice control data structure. The bitstream data buffer shall not contain NAL units with values of nal_unit_type outside the range [1 .. 8]. However, the accelerator shall allow any such NAL units to be present and should ignore their content if present.
315     *   Note: The bitstream data buffer shall contain the full NAL unit byte stream, either encrpted or clear. This means that the buffer will contain emulation_prevention_three_byte syntax elements where those elements are required to be present in a NAL unit, as defined in the HEVC specification. The bitstream data buffer may or may not contrain leading_zero_8bits, zero_byte, and trailing_zero_8bits syntax elements. If present, the accelerator shall ignore these elements.
316     */
317     uint32_t                slice_data_offset;
318     /*! \brief This member indicated if current slice is complete.
319     *
320     *   0 - Complete; 1 - Partial slice data with the start of slice; 2 - Partial slice data with the end of slice; 3 - Partial slice data with the middle of slice;
321     */
322     uint16_t                slice_chopping;
323 
324     // Long format specific
325     uint16_t                NumEmuPrevnBytesInSliceHdr;           //!< Number of emulation prevention bytes in slice head; ByteOffsetToSliceData doesn't include these bytes.
326     /*! \brief Byte offset to the location of the first byte of slice_data() data structure for the current slice in the bitstream data buffer.
327     *
328     *   This byte offset is the offset within the RBSP date for the slice, relative to the starting position of the slice_header() in the RBSP. That is, it represents a byte offset after the removal of any emulation_prevention_three_byte syntax elements that precedes the start of the slice_data() in the NAL unit.
329     */
330     uint32_t                ByteOffsetToSliceData;
331     /*! \brief Same as HEVC syntax element.
332     *
333     *   For first slice in the picture, slice_segment_address shall be set to 0.
334     */
335     uint32_t                slice_segment_address;
336     /*! \brief Specifies the surfaces of reference pictures
337     *
338     *   The value of FrameIdx specifies the index of RefFrameList structure. And valid value range is [0..14, 0x7F]. Invalid entries are indicated by setting PicFlags to PICTURE_INVALID and the PicFlags value of PICTURE_LONG_TERM_REFERENCE has no meaning.
339     *   RefPicIdx[0][] corresponds to reference list 0.
340     *   RefPicIdx[1][] corresponds to reference list 1.
341     *   Each list may contain duplicated reference picture indexes.
342     */
343     CODEC_PICTURE       RefPicList[2][15];
344     union
345     {
346         uint32_t            value;
347         struct
348         {
349             uint32_t        LastSliceOfPic                               : 1;   //!< Specifies if current slice is the last slice of picture.
350             uint32_t        dependent_slice_segment_flag                 : 1;   //!< Same as HEVC syntax element
351             uint32_t        slice_type                                   : 2;   //!< Same as HEVC syntax element
352             uint32_t        color_plane_id                               : 2;   //!< Same as HEVC syntax element
353             uint32_t        slice_sao_luma_flag                          : 1;   //!< Same as HEVC syntax element
354             uint32_t        slice_sao_chroma_flag                        : 1;   //!< Same as HEVC syntax element
355             uint32_t        mvd_l1_zero_flag                             : 1;   //!< Same as HEVC syntax element
356             uint32_t        cabac_init_flag                              : 1;   //!< Same as HEVC syntax element
357             uint32_t        slice_temporal_mvp_enabled_flag              : 1;   //!< Same as HEVC syntax element
358             uint32_t        slice_deblocking_filter_disabled_flag        : 1;   //!< Same as HEVC syntax element
359             uint32_t        collocated_from_l0_flag                      : 1;   //!< Same as HEVC syntax element
360             uint32_t        slice_loop_filter_across_slices_enabled_flag : 1;   //!< Same as HEVC syntax element
361             uint32_t        reserved                                     : 18;  //!< Value is used for alignemnt and has no meaning, set to 0.
362         }fields;
363     }LongSliceFlags;
364 
365     /*! \brief Index to the RefPicList[0][] or RefPicList[1][].
366     *
367     *   It should be derived from HEVC syntax element collocated_ref_idx. When the HEVC syntax element slice_temporal_mvp_enabled_flag takes value 0,  collocated_ref_idx should take value 0xFF. Valid value range is [0.. num_ref_idx_l0_active_minus1] or [0..num_ref_idx_l1_active_minus1] depending on collocated_from_l0_flag. If collocated_ref_idx takes a valid value, the corresponding entry of RefFrameList[] must contain a valid surface index.
368     */
369     uint8_t             collocated_ref_idx;
370     /*! \brief Same as HEVC syntax element.
371     *
372     *   If num_ref_idx_active_override_flag == 0, host decoder shall set their values with num_ref_idx_l0_default_minus1, and num_ref_idx_l1_default_minus1.
373     */
374     uint8_t             num_ref_idx_l0_active_minus1;
375     /*! \brief Same as HEVC syntax element.
376     *
377     *   If num_ref_idx_active_override_flag == 0, host decoder shall set their values with num_ref_idx_l0_default_minus1, and num_ref_idx_l1_default_minus1.
378     */
379     uint8_t             num_ref_idx_l1_active_minus1;
380     char                slice_qp_delta;                 //!< Same as HEVC syntax element
381     char                slice_cb_qp_offset;             //!< Same as HEVC syntax element
382     char                slice_cr_qp_offset;             //!< Same as HEVC syntax element
383     char                slice_beta_offset_div2;         //!< Same as HEVC syntax element
384     char                slice_tc_offset_div2;           //!< Same as HEVC syntax element
385     /*! \brief Same as HEVC syntax element.
386     *
387     *   Specifies the base 2 logarithm of the denominator for all luma weighting factors. Value range: 0 to 7, inclusive.
388     */
389     uint8_t             luma_log2_weight_denom;
390     /*! \brief Same as HEVC syntax element.
391     *
392     *   Specifies the base 2 logarithm of the denominator for all chroma weighting factors. Value range of luma_log2_weight_denom + delta_chroma_log2_weight_denom: 0 to 7, inclusive.
393     */
394     uint8_t             delta_chroma_log2_weight_denom;
395 
396     /*! \brief Same as HEVC syntax element.
397     *
398     *   If the corresponding luma or chroma weight flags are 0, the value should also be set to default value according to HEVC specification.
399     */
400     char                delta_luma_weight_l0[15];
401     /*! \brief Same as HEVC syntax element.
402     *
403     *   If the corresponding luma or chroma weight flags are 0, the value should also be set to default value according to HEVC specification.
404     */
405     char                luma_offset_l0[15];
406     /*! \brief Same as HEVC syntax element.
407     *
408     *   If the corresponding luma or chroma weight flags are 0, the value should also be set to default value according to HEVC specification.
409     */
410     char                delta_chroma_weight_l0[15][2];
411     /*! \brief Same as HEVC syntax element.
412     *
413     *   If the corresponding chroma weight flags are 0, the value should also be set to 0. Please note that for range extension profiles other than main, main10, and their related intra or still image profiles, the data types are defined differrently.
414     */
415     char                ChromaOffsetL0[15][2];
416 
417     /*! \brief Same as HEVC syntax element.
418     *
419     *   If the corresponding luma or chroma weight flags are 0, the value should also be set to default value according to HEVC specification.
420     */
421     char                delta_luma_weight_l1[15];
422     /*! \brief Same as HEVC syntax element.
423     *
424     *   If the corresponding luma or chroma weight flags are 0, the value should also be set to default value according to HEVC specification.
425     */
426     char                luma_offset_l1[15];
427     /*! \brief Same as HEVC syntax element.
428     *
429     *   If the corresponding luma or chroma weight flags are 0, the value should also be set to default value according to HEVC specification.
430     */
431     char                delta_chroma_weight_l1[15][2];
432     /*! \brief Same as HEVC syntax element.
433     *
434     *   If the corresponding chroma weight flags are 0, the value should also be set to 0. Please note that for range extension profiles other than main, main10, and their related intra or still image profiles, the data types are defined differrently.
435     */
436     char                ChromaOffsetL1[15][2];
437 
438     /*! \brief Same as HEVC syntax element.
439     *
440     *   HEVC spec variable MaxNumMergeCand can be derived by 5 - five_minus_max_num_merge_cand, and specifies the maximum number of merging MVP candidates supported in the slice. Value range: 0 to 4 inclusive.
441     */
442     uint8_t             five_minus_max_num_merge_cand;
443     uint16_t            num_entry_point_offsets;                // [0..540]
444     uint16_t            EntryOffsetToSubsetArray;               // [0..540]
445 } CODEC_HEVC_SLICE_PARAMS, *PCODEC_HEVC_SLICE_PARAMS;
446 
447 /*! \brief Short Format Slice-level parameters of a compressed picture for HEVC decoding.
448 *
449 *   The slice control buffer is accompanied by a raw bitstream data buffer. The total quantity of data in the bitstream buffer (and the amount of data reported by the host decoder) shall be an integer multiple of 128 bytes.
450 */
451 typedef struct _CODEC_HEVC_SF_SLICE_PARAMS
452 {
453     /*! \brief Number of bytes in the bitstream data buffer that are associated with this slice control data structure.
454     *
455     *   Starting with the byte at the offset given in slice_data_offset. The bitstream data buffer shall not contain additional byte stream NAL units in the bytes following BSNALunitDataLocation up to the location slice_data_offset + slice_data_size. If slice_data_offset + slice_data_size exceeds the boundary of current bitstream data buffer, the excess slice bytes should continue from the first byte of next bitstream data buffer.
456     */
457     uint32_t slice_data_size;
458     /*! \brief This member locates the NAL unit with nal_unit_type equal to 1 .. 8 for the current slice.
459     *
460     *   At least one bit stream data buffer should be present which is associated with the slice control data buffer. If necessary, multiple bit stream data buffers are allowed, but not suggested. The size of the data in the bitstream data buffer (and the amount of data reported by the host decoder) shall be an integer multiple of 128 bytes. When  the end of the slice data is not an even multiple of 128 bytes, the decoder should pad the end of the buffer with zeroes.  When more than one bitstream data buffers are present, these data buffers should be in sequential order. They should be treated as if concatenated linearly with no space in between.  The value of slice_data_offset is the byte offset, from the start of the first bitstream data buffer, of the first byte of the start code prefix in the byte stream NAL unit that contains the NAL unit with nal_unit_type equal to 1 .. 8. The current slice is the slice associated with this slice control data structure. The bitstream data buffer shall not contain NAL units with values of nal_unit_type outside the range [1 .. 8]. However, the accelerator shall allow any such NAL units to be present and should ignore their content if present.
461     *   Note: The bitstream data buffer shall contain the full NAL unit byte stream, either encrpted or clear. This means that the buffer will contain emulation_prevention_three_byte syntax elements where those elements are required to be present in a NAL unit, as defined in the HEVC specification. The bitstream data buffer may or may not contrain leading_zero_8bits, zero_byte, and trailing_zero_8bits syntax elements. If present, the accelerator shall ignore these elements.
462     */
463     uint32_t slice_data_offset;
464     /*! \brief This member indicated if current slice is complete.
465     *
466     *   0 - Complete; 1 - Partial slice data with the start of slice; 2 - Partial slice data with the end of slice; 3 - Partial slice data with the middle of slice;
467     */
468     uint16_t slice_chopping;
469 } CODEC_HEVC_SF_SLICE_PARAMS, *PCODEC_HEVC_SF_SLICE_PARAMS;
470 
471 /*! \brief Additional picture-level parameters of a compressed picture for HEVC decoding.
472 *
473 *   Defined for profiles main12, main4:2:2 10, main4:2:2 12, main4:4:4, main4:4:4 10, main4:4:4 12 and their related intra and still picture profiles.
474 */
475 typedef struct _CODEC_HEVC_EXT_PIC_PARAMS
476 {
477     union
478     {
479         struct
480         {
481             uint32_t        transform_skip_rotation_enabled_flag : 1;    //!< Same as HEVC syntax element
482             uint32_t        transform_skip_context_enabled_flag : 1;    //!< Same as HEVC syntax element
483             uint32_t        implicit_rdpcm_enabled_flag : 1;    //!< Same as HEVC syntax element
484             uint32_t        explicit_rdpcm_enabled_flag : 1;    //!< Same as HEVC syntax element
485             uint32_t        extended_precision_processing_flag : 1;    //!< Same as HEVC syntax element
486             uint32_t        intra_smoothing_disabled_flag : 1;    //!< Same as HEVC syntax element
487             uint32_t        high_precision_offsets_enabled_flag : 1;    //!< Same as HEVC syntax element
488             uint32_t        persistent_rice_adaptation_enabled_flag : 1;    //!< Same as HEVC syntax element
489             uint32_t        cabac_bypass_alignment_enabled_flag : 1;    //!< Same as HEVC syntax element
490             uint32_t        cross_component_prediction_enabled_flag : 1;    //!< Same as HEVC syntax element
491             uint32_t        chroma_qp_offset_list_enabled_flag : 1;    //!< Same as HEVC syntax element
492             uint32_t        BitDepthLuma16 : 1;    //!< Same as HEVC syntax element
493             uint32_t        BitDepthChroma16 : 1;    //!< Same as HEVC syntax element
494             uint32_t        ReservedBits5 : 19;   //!< Value is used for alignemnt and has no meaning, set to 0.
495         } fields;
496         uint32_t            dwRangeExtensionPropertyFlags;
497     } PicRangeExtensionFlags;
498 
499     uint8_t            diff_cu_chroma_qp_offset_depth;             //!< Same as HEVC syntax element, [0..3]
500     uint8_t            chroma_qp_offset_list_len_minus1;           //!< Same as HEVC syntax element, [0..5]
501     uint8_t            log2_sao_offset_scale_luma;                 //!< Same as HEVC syntax element, [0..6]
502     uint8_t            log2_sao_offset_scale_chroma;               //!< Same as HEVC syntax element, [0..6]
503     uint8_t         log2_max_transform_skip_block_size_minus2;  //!< Same as HEVC syntax element
504     char            cb_qp_offset_list[6];                       //!< Same as HEVC syntax element, [-12..12]
505     char            cr_qp_offset_list[6];                       //!< Same as HEVC syntax element, [-12..12]
506 } CODEC_HEVC_EXT_PIC_PARAMS, *PCODEC_HEVC_EXT_PIC_PARAMS;
507 
508 
509 /*! \brief Additional range extention slice-level parameters of a compressed picture for HEVC decoding.
510 *
511 *   HEVC range extension profiles extend the luma and chroma offset values from 8 bits to 16 bits.
512 */
513 typedef struct _CODEC_HEVC_EXT_SLICE_PARAMS
514 {
515     /*! \brief Same as HEVC syntax element.
516     *
517     *   These set of values are the most significant 8-bit part of the corresponding luma_offset_l0[]. Combining with the luma_offset_l0[] will give the final values respectively.  The sign for each parameter is determined by the sign of corresponding luma_offset_l0[].
518     */
519     int16_t                luma_offset_l0[15];
520     /*! \brief Same as HEVC syntax element.
521     *
522     *   These set of values are the most significant 8-bit part of the corresponding chroma_offset_l0[]. Combining with the chroma_offset_l0[] will give the final values respectively.  The sign for each parameter is determined by the sign of corresponding chroma_offset_l0[].
523     */
524     int16_t                ChromaOffsetL0[15][2];
525     /*! \brief Same as HEVC syntax element.
526     *
527     *   These set of values are the most significant 8-bit part of the corresponding luma_offset_l1[]. Combining with the luma_offset_l1[] will give the final values respectively.  The sign for each parameter is determined by the sign of corresponding luma_offset_l1[].
528     */
529     int16_t                luma_offset_l1[15];
530     /*! \brief Same as HEVC syntax element.
531     *
532     *   These set of values are the most significant 8-bit part of the corresponding chroma_offset_l1[]. Combining with the chroma_offset_l1[] will give the final values respectively.  The sign for each parameter is determined by the sign of corresponding chroma_offset_l1[].
533     */
534     int16_t                ChromaOffsetL1[15][2];
535 
536     bool                   cu_chroma_qp_offset_enabled_flag;  //!< Same as HEVC syntax element
537 
538                                                               // For Screen Content Extension
539     char                   slice_act_y_qp_offset;      // [-12..12]
540     char                   slice_act_cb_qp_offset;     // [-12..12]
541     char                   slice_act_cr_qp_offset;     // [-12..12]
542     unsigned char          use_integer_mv_flag;
543 } CODEC_HEVC_EXT_SLICE_PARAMS, *PCODEC_HEVC_EXT_SLICE_PARAMS;
544 
545 typedef struct _CODEC_HEVC_SUBSET_PARAMS
546 {
547     uint32_t                 entry_point_offset_minus1[440];
548 } CODEC_HEVC_SUBSET_PARAMS, *PCODEC_HEVC_SUBSET_PARAMS;
549 #endif  // __CODEC_DEF_DECODE_HEVC_H__
550