| 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_avc.h |
| 24 |
//! \brief Defines decode AVC types and macros shared by CodecHal, MHW, and DDI layer |
| 25 |
//! \details Applies to AVC decode only. Should not contain any DDI specific code. |
| 26 |
//! |
| 27 |
#ifndef __CODEC_DEF_DECODE_AVC_H__ |
| 28 |
#define __CODEC_DEF_DECODE_AVC_H__ |
| 29 |
|
| 30 |
#include "codec_def_common_avc.h" |
| 31 |
|
| 32 |
//Check whether interview prediction is used through POC |
| 33 |
#define CodecHal_IsInterviewPred(currPic, currPoc, avcRefListIdx) ( ((avcRefListIdx)!=(currPic).FrameIdx) && \ |
| 34 |
(!CodecHal_PictureIsTopField(currPic) && (ppAvcRefList[avcRefListIdx]->iFieldOrderCnt[1] == (currPoc)[1]) || \ |
| 35 |
!CodecHal_PictureIsBottomField(currPic) && (ppAvcRefList[avcRefListIdx]->iFieldOrderCnt[0] == (currPoc)[0])) && \ |
| 36 |
((currPic).FrameIdx != 0x7f)) |
| 37 |
|
| 38 |
typedef struct _CODEC_AVC_DMV_LIST |
| 39 |
{ |
| 40 |
uint8_t ucFrameId; |
| 41 |
bool bInUse; |
| 42 |
bool bReUse; |
| 43 |
} CODEC_AVC_DMV_LIST, *PCODEC_AVC_DMV_LIST; |
| 44 |
|
| 45 |
//! |
| 46 |
//! \enum AvcChromaFormatIdc |
| 47 |
//! \brief AVC chroma format Idc |
| 48 |
//! |
| 49 |
enum AvcChromaFormatIdc |
| 50 |
{ |
| 51 |
avcChromaFormatMono = 0, |
| 52 |
avcChromaFormat420 = 1, |
| 53 |
avcChromaFormat422 = 2, |
| 54 |
avcChromaFormat444 = 3, |
| 55 |
}; |
| 56 |
|
| 57 |
// H.264 Picture Parameters Buffer |
| 58 |
typedef struct _CODEC_AVC_PIC_PARAMS |
| 59 |
{ |
| 60 |
/*! \brief Uncompressed destination surface of the frame for the current decoded picture. |
| 61 |
* |
| 62 |
* 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. |
| 63 |
*/ |
| 64 |
CODEC_PICTURE CurrPic; |
| 65 |
/*! \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. |
| 66 |
* |
| 67 |
* 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. |
| 68 |
* 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. |
| 69 |
*/ |
| 70 |
CODEC_PICTURE RefFrameList[CODEC_AVC_MAX_NUM_REF_FRAME]; |
| 71 |
|
| 72 |
uint16_t pic_width_in_mbs_minus1; //!< Same as AVC syntax element. |
| 73 |
/*! \brief The height of the frame in MBs minus 1. |
| 74 |
* |
| 75 |
* Derived from pic_height_in_map_units_minus1: pic_height_in_map_units_minus1 << uint16_t(frame_mbs_only_flag == 0) |
| 76 |
*/ |
| 77 |
uint16_t pic_height_in_mbs_minus1; |
| 78 |
uint8_t bit_depth_luma_minus8; //!< Same as AVC syntax element. |
| 79 |
uint8_t bit_depth_chroma_minus8; //!< Same as AVC syntax element. |
| 80 |
uint8_t num_ref_frames; //!< Same as AVC syntax element. |
| 81 |
/*! \brief Contains the picture order counts (POC) for the current frame |
| 82 |
* |
| 83 |
* If field_pic_flag is 0: |
| 84 |
* \n - CurrFieldOrderCnt[0] contains the top field order count for the current picture |
| 85 |
* \n - CurrFieldOrderCnt[1] contains the bottom field order count for the current picture |
| 86 |
* \n If field_pic_flag is 1 and CurrPic.PicFlags indicates that this is a top field: |
| 87 |
* \n - CurrFieldOrderCnt[0] contains the top field order count for the current picture |
| 88 |
* \n - CurrFieldOrderCnt[1] |
| 89 |
* \n If field_pic_flag is 1 and CurrPic.PicFlags indicates that this is a bottom field: |
| 90 |
* \n - CurrFieldOrderCnt[0] should be 0 or ignored |
| 91 |
* \n - CurrFieldOrderCnt[1] contains the bottom field order count for the current picture |
| 92 |
*/ |
| 93 |
int32_t CurrFieldOrderCnt[2]; |
| 94 |
/*! \brief Contains the POCs for the reference frames in RefFrameList. |
| 95 |
* |
| 96 |
* For each entry FieldOrderCntList[i][j]: |
| 97 |
* \n - i: the picture index |
| 98 |
* \n - j: 0 specifies the top field order count and 1 specifies the bottom field order count |
| 99 |
* \n If a entry i in RefFrameList is not relevant (it is not used for reference) or valid, the entry FieldOrderCount[i][0 and 1] should be 0. |
| 100 |
*/ |
| 101 |
int32_t FieldOrderCntList[16][2]; |
| 102 |
|
| 103 |
union |
| 104 |
{ |
| 105 |
struct |
| 106 |
{ |
| 107 |
uint32_t chroma_format_idc : 2; //!< Same as AVC syntax element. |
| 108 |
uint32_t residual_colour_transform_flag : 1; //!< Same as AVC syntax element. |
| 109 |
uint32_t frame_mbs_only_flag : 1; //!< Same as AVC syntax element. |
| 110 |
uint32_t mb_adaptive_frame_field_flag : 1; //!< Same as AVC syntax element. |
| 111 |
uint32_t direct_8x8_inference_flag : 1; //!< Same as AVC syntax element. |
| 112 |
uint32_t : 1; |
| 113 |
uint32_t log2_max_frame_num_minus4 : 4; //!< Same as AVC syntax element. |
| 114 |
uint32_t pic_order_cnt_type : 2; //!< Same as AVC syntax element. |
| 115 |
uint32_t log2_max_pic_order_cnt_lsb_minus4 : 4; //!< Same as AVC syntax element. |
| 116 |
uint32_t delta_pic_order_always_zero_flag : 1; //!< Same as AVC syntax element. |
| 117 |
}; |
| 118 |
uint32_t value; |
| 119 |
} seq_fields; |
| 120 |
|
| 121 |
uint8_t num_slice_groups_minus1; //!< Same as AVC syntax element. |
| 122 |
uint8_t slice_group_map_type; //!< Same as AVC syntax element. |
| 123 |
uint16_t slice_group_change_rate_minus1; //!< Same as AVC syntax element. |
| 124 |
char pic_init_qp_minus26; //!< Same as AVC syntax element. |
| 125 |
char chroma_qp_index_offset; //!< Same as AVC syntax element. |
| 126 |
char second_chroma_qp_index_offset; //!< Same as AVC syntax element. |
| 127 |
|
| 128 |
union |
| 129 |
{ |
| 130 |
struct |
| 131 |
{ |
| 132 |
uint32_t entropy_coding_mode_flag : 1; //!< Same as AVC syntax element. |
| 133 |
uint32_t weighted_pred_flag : 1; //!< Same as AVC syntax element. |
| 134 |
uint32_t weighted_bipred_idc : 2; //!< Same as AVC syntax element. |
| 135 |
uint32_t transform_8x8_mode_flag : 1; //!< Same as AVC syntax element. |
| 136 |
uint32_t field_pic_flag : 1; //!< Same as AVC syntax element. |
| 137 |
uint32_t constrained_intra_pred_flag : 1; //!< Same as AVC syntax element. |
| 138 |
uint32_t pic_order_present_flag : 1; //!< Same as AVC syntax element. |
| 139 |
uint32_t deblocking_filter_control_present_flag : 1; //!< Same as AVC syntax element. |
| 140 |
uint32_t redundant_pic_cnt_present_flag : 1; //!< Same as AVC syntax element. |
| 141 |
uint32_t reference_pic_flag : 1; //!< Same as AVC syntax element. |
| 142 |
uint32_t IntraPicFlag : 1; //!< All MBs in frame use intra prediction mode. |
| 143 |
}; |
| 144 |
uint32_t value; |
| 145 |
} pic_fields; |
| 146 |
|
| 147 |
// Short format specific |
| 148 |
uint8_t num_ref_idx_l0_active_minus1; //!< Same as AVC syntax element. |
| 149 |
uint8_t num_ref_idx_l1_active_minus1; //!< Same as AVC syntax element. |
| 150 |
/*! \brief Contains the value of FrameNum or LongTermRefIdx depending on the PicFlags for the frame. |
| 151 |
* |
| 152 |
* Each entry in FrameNumList has a corresponding entry in RefFrameList, if an entry in RefFrameList is not relevant (it is not used for reference) or valid, the entry in FrameNumList should be 0. |
| 153 |
*/ |
| 154 |
uint16_t FrameNumList[16]; |
| 155 |
/*! \brief Denotes "non-existing" frames as defined in the AVC specification. |
| 156 |
* |
| 157 |
* The flag is accessed by: Flag(i) = (NonExistingFrameFlags >> i) & 1. If Flag(i) is 1, frame i is marked as "non-existing", otherwise the frame is existing. |
| 158 |
*/ |
| 159 |
uint16_t NonExistingFrameFlags; |
| 160 |
/*! \brief Denotes "used for reference" frames as defined in the AVC specification. |
| 161 |
* |
| 162 |
* The flag is accessed by: |
| 163 |
* \n - FlagTop(i) = (UsedForReferenceFlags >> (2 * i)) & 1 |
| 164 |
* \n - FlagBottom(i) = (UsedForReferenceFlags >> (2 * i + 1)) & 1 |
| 165 |
* \n If FlagTop(i) is 1, the top field or frame numger i is marked as "used for reference"; if FlagBottom(i) is 1 then then bottom field of frame i is marked as "used for reference". If either is 0 then the frame is not marked as "used for reference". |
| 166 |
*/ |
| 167 |
uint32_t UsedForReferenceFlags; |
| 168 |
uint16_t frame_num; //!< Same as AVC syntax element. |
| 169 |
|
| 170 |
/*! \brief Arbitrary number set by the host decoder to use as a tag in the status report feedback data. |
| 171 |
* |
| 172 |
* The value should not equal 0, and should be different in each call to Execute. |
| 173 |
*/ |
| 174 |
uint32_t StatusReportFeedbackNumber; |
| 175 |
} CODEC_AVC_PIC_PARAMS, *PCODEC_AVC_PIC_PARAMS; |
| 176 |
|
| 177 |
// H.264 Decode Slice Parameter Buffer (Long/Short format) |
| 178 |
typedef struct _CODEC_AVC_SLICE_PARAMS |
| 179 |
{ |
| 180 |
uint32_t slice_data_size; //!< Number of bytes in the bitstream buffer for this slice. |
| 181 |
uint32_t slice_data_offset; //!< The offset to the NAL start code for this slice. |
| 182 |
|
| 183 |
// Long format specific |
| 184 |
uint16_t slice_data_bit_offset; //!< Bit offset from NAL start code to the beginning of slice data. |
| 185 |
uint16_t first_mb_in_slice; //!< Same as AVC syntax element. |
| 186 |
uint16_t NumMbsForSlice; //!< Number of MBs in the bitstream associated with this slice. |
| 187 |
uint8_t slice_type; //!< Same as AVC syntax element. |
| 188 |
uint8_t direct_spatial_mv_pred_flag; //!< Same as AVC syntax element. |
| 189 |
uint8_t num_ref_idx_l0_active_minus1; //!< Same as AVC syntax element. |
| 190 |
uint8_t num_ref_idx_l1_active_minus1; //!< Same as AVC syntax element. |
| 191 |
uint8_t cabac_init_idc; //!< Same as AVC syntax element. |
| 192 |
char slice_qp_delta; //!< Same as AVC syntax element. |
| 193 |
uint8_t disable_deblocking_filter_idc; //!< Same as AVC syntax element. |
| 194 |
char slice_alpha_c0_offset_div2; //!< Same as AVC syntax element. |
| 195 |
char slice_beta_offset_div2; //!< Same as AVC syntax element. |
| 196 |
/*! \brief Specifies the reference picture lists 0 and 1 |
| 197 |
* |
| 198 |
* Contains field/frame information concerning the reference in PicFlags. RefPicList[i][j]: |
| 199 |
* \n - i: the reference picture list (0 or 1) |
| 200 |
* \n - j: if the PicFlags are not PICTURE_INVALID, the index variable j is a reference to entry j in teh reference picture list. |
| 201 |
*/ |
| 202 |
CODEC_PICTURE RefPicList[2][32]; |
| 203 |
uint8_t luma_log2_weight_denom; //!< Same as AVC syntax element. |
| 204 |
uint8_t chroma_log2_weight_denom; //!< Same as AVC syntax element. |
| 205 |
/*! \brief Specifies the weights and offsets used for explicit mode weighted prediction. |
| 206 |
* |
| 207 |
* Weigths[i][j][k][m]: |
| 208 |
* \n - i: the reference picture list (0 or 1) |
| 209 |
* \n - j: reference to entry j in RefPicList (has range [0...31]) |
| 210 |
* \n - k: the YUV component (0 = luma, 1 = Cb chroma, 2 = Cr chroma) |
| 211 |
* \n - m: the weight or offset used in the weighted prediction process (0 = weight, 1 = offset) |
| 212 |
*/ |
| 213 |
int16_t Weights[2][32][3][2]; |
| 214 |
uint16_t slice_id; //!< Same as AVC syntax element. |
| 215 |
uint16_t first_mb_in_next_slice; //!< If there is a subsequent slice, specifies first_mb_in_slice for the next slice, otherwise is 0. |
| 216 |
} CODEC_AVC_SLICE_PARAMS, *PCODEC_AVC_SLICE_PARAMS; |
| 217 |
|
| 218 |
typedef struct _CODEC_AVC_SF_SLICE_PARAMS |
| 219 |
{ |
| 220 |
uint32_t slice_data_size; //!< Number of bytes in the bitstream buffer for this slice. |
| 221 |
uint32_t slice_data_offset; //!< The offset to the NAL start code for this slice. |
| 222 |
} CODEC_AVC_SF_SLICE_PARAMS, *PCODEC_AVC_SF_SLICE_PARAMS; |
| 223 |
|
| 224 |
// AVC MVC Extension Picture Parameter Set |
| 225 |
// (sent along with regular _CODEC_AVC_PIC_PARAMS) |
| 226 |
typedef struct _CODEC_MVC_EXT_PIC_PARAMS |
| 227 |
{ |
| 228 |
uint16_t CurrViewID; |
| 229 |
uint8_t anchor_pic_flag; |
| 230 |
uint8_t inter_view_flag; |
| 231 |
uint8_t NumInterViewRefsL0; |
| 232 |
uint8_t NumInterViewRefsL1; |
| 233 |
union |
| 234 |
{ |
| 235 |
uint8_t bPicFlags; |
| 236 |
struct |
| 237 |
{ |
| 238 |
uint8_t SwitchToAVC : 1; |
| 239 |
uint8_t Reserved7Bits : 7; |
| 240 |
}; |
| 241 |
}; |
| 242 |
uint8_t Reserved8Bits; |
| 243 |
uint16_t ViewIDList[16]; |
| 244 |
uint16_t InterViewRefList[2][16]; |
| 245 |
} CODEC_MVC_EXT_PIC_PARAMS, *PCODEC_MVC_EXT_PIC_PARAMS; |
| 246 |
|
| 247 |
#endif // __CODEC_DEF_DECODE_AVC_H__ |