1 /* 2 * Copyright (c) 2011 Intel Corporation. All Rights Reserved. 3 * Copyright (c) Imagination Technologies Limited, UK 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sub license, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the 14 * next paragraph) shall be included in all copies or substantial portions 15 * of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * 25 * Authors: 26 * Waldo Bastian <waldo.bastian@intel.com> 27 * 28 */ 29 30 #ifndef _VC1_HEADER_H_ 31 #define _VC1_HEADER_H_ 32 33 #include "psb_def.h" 34 #include "tng_vld_dec.h" 35 36 #include <img_types.h> 37 38 39 /* Picture header parameters */ 40 typedef struct _vc1PicHeader_ { 41 /* TTMBF signals whether transform type coding is enabled at the frame or macroblock level. */ 42 IMG_UINT8 TTMBF; /* PICTURE_LAYER::TTMBF - 1 bit */ 43 /* TTFRM signals the transform type used to transform the 8x8 pixel error signal in predicted blocks. */ 44 IMG_UINT8 TTFRM; /* PICTURE_LAYER::TTFRM - 2 bits */ 45 /* 46 BFRACTION signals a fraction that may take on a limited set of fractional values between 0 and 1, 47 denoting the relative temporal position of the B frame within the interval formed by its anchors. 48 */ 49 IMG_UINT8 BFRACTION; /* PICTURE_LAYER::BFRACTION - 2 bits */ 50 /* 51 CONDOVER affects overlap smoothing in advanced profile. 52 */ 53 IMG_UINT8 CONDOVER; /* PICTURE_LAYER::CONDOVER - 2 bits */ 54 55 /* 56 TRANSACFRM shall provide the index that selects the coding set used to decode the 57 Transform AC coefficients for the Cb, Cr blocks. 58 */ 59 IMG_UINT8 TRANSACFRM; /* PICTURE_LAYER::TRANSACFRM - 2 bits */ 60 /* 61 TRANSACFRM2 shall provide the index that selects the coding set used to decode the 62 Transform AC coefficients for the Y blocks. 63 */ 64 IMG_UINT8 TRANSACFRM2; /* PICTURE_LAYER::TRANSACFRM2 - 2 bits */ 65 /* 66 MVMODE syntax element shall signal one of four motion vector coding modes, 67 or the intensity compensation mode. 68 */ 69 IMG_UINT8 MVMODE; /* PICTURE_LAYER::MVMODE - 2 bits */ 70 IMG_UINT8 MVMODE2; /* PICTURE_LAYER::MVMODE2 - 2 bits */ 71 72 /* These are needed just for finding out what VLC tables are used in the current picture */ 73 IMG_UINT8 MV4SWITCH; /* PICTURE_LAYER::MV4SWITCH - 1 bit */ 74 IMG_UINT8 CBPTAB; /* PICTURE_LAYER::CBPTAB - 2 bits */ 75 IMG_UINT8 ICBPTAB; /* PICTURE_LAYER::ICBPTAB - 3 bits */ 76 IMG_UINT8 MVTAB; /* PICTURE_LAYER::MVTAB - 2 bits */ 77 IMG_UINT8 IMVTAB; /* PICTURE_LAYER::IMVTAB - 3 bits */ 78 IMG_UINT8 MV4BPTAB; /* PICTURE_LAYER::4MVBPTAB - 2 bits */ 79 IMG_UINT8 MV2BPTAB; /* PICTURE_LAYER::2MVBPTAB - 2 bits */ 80 IMG_UINT8 MBMODETAB; /* PICTURE_LAYER::MBMODETAB - 3 bits */ 81 IMG_UINT8 TRANSDCTAB; /* PICTURE_LAYER::TRANSDCTAB - 1 bits */ 82 83 /* PQINDEX is used in VLD and the hardware actually only needs to know if it is greater than 8 or not. */ 84 IMG_UINT8 PQINDEX; /* PICTURE_LAYER::PQINDEX - 5 bits */ 85 /* 86 HALFQP syntax element allows the picture quantizer to be expressed in half step increments. 87 If HALFQP == 1, then the picture quantizer step size shall be equal to PQUANT + 1/2. If 88 HALFQP == 0, then the picture quantizer step size shall be equal to PQUANT. 89 */ 90 IMG_UINT8 HALFQP; /* PICTURE_LAYER::HALFQP - 1 bit */ 91 92 IMG_UINT8 bNonUniformQuantizer; 93 IMG_UINT8 VOPDQUANT_Present; 94 IMG_UINT8 bDQUANT_InFrame; // Indicates whether quantisation can be specified at a MB level 95 /* If DQUANTFRM == 0, then the current picture shall only be quantized with PQUANT. */ 96 IMG_UINT8 DQUANTFRM; /* VOPDQUANT::DQUANTFRM - 1 bit */ 97 /* DQPROFILE specifies where it is allowable to change quantization step sizes within the current picture. */ 98 IMG_UINT8 DQPROFILE; /* VOPDQUANT::DQPROFILE - 2 bits */ 99 /* 100 DQBILEVEL determines the number of possible quantization step sizes which can be 101 used by each macroblock in the frame. 102 */ 103 IMG_UINT8 DQBILEVEL; /* VOPDQUANT::DQBILEVEL - 1 bit */ 104 /* DQDBEDGE specifies which two edges will be quantized with ALTPQUANT when DQPROFILE == 'Double Edge'. */ 105 IMG_UINT8 DQDBEDGE; /* VOPDQUANT::DQDBEDGE - 2 bits */ 106 /* DQSBEDGE specifies which edge will be quantized with ALTPQUANT when DQPROFILE == 'Single Edge'. */ 107 IMG_UINT8 DQSBEDGE; /* VOPDQUANT::DQSBEDGE - 2 bits */ 108 IMG_UINT8 ALTPQUANT; /* VOPDQUANT::ALTPQUANT - 5 bits */ 109 110 /* REFDIST defines the number of frames between the current frame and the reference frame. */ 111 IMG_UINT8 REFDIST; /* PICTURE_LAYER::REFDIST - 1 bit */ 112 /* 113 If NUMREF == 0, then the current interlace P field picture shall reference one field. If 114 NUMREF == 1, then the current interlace P field picture shall reference the two temporally 115 closest (in display order) I or P field pictures. 116 */ 117 IMG_UINT8 NUMREF; /* PICTURE_LAYER::NUMREF - 1 bit */ 118 /* 119 If REFFIELD == 1, then the second most temporally recent interlace I or P field picture 120 shall be used as reference. 121 */ 122 IMG_UINT8 REFFIELD; /* PICTURE_LAYER::REFFIELD - 1 bit */ 123 124 /* MVRANGE specifies the motion vector range. */ 125 IMG_UINT8 MVRANGE; /* PICTURE_LAYER::MVRANGE - 2 bits */ 126 /* 127 DMVRANGE indicates if the extended range for motion vector differential is used in the 128 vertical, horizontal, both or none of the components of the motion vector. 129 */ 130 IMG_UINT8 DMVRANGE; /* PICTURE_LAYER::DMVRANGE - 2 bits */ 131 132 /* BitplanePresent indicates which bitplanes are present in the picture header */ 133 IMG_UINT8 BP_PRESENT; 134 /* RawCodingFlag signals whether the bitplanes are coded in raw mode (bit set to 1) or not (set to 0) */ 135 IMG_UINT8 RAWCODINGFLAG; 136 137 } vc1PicHeader; 138 139 /* Sequence header parameters */ 140 typedef struct _vc1SeqHeader_ { 141 IMG_UINT8 POSTPROCFLAG; 142 IMG_UINT8 PULLDOWN; 143 IMG_UINT8 INTERLACE; 144 IMG_UINT8 TFCNTRFLAG; 145 IMG_UINT8 FINTERPFLAG; 146 IMG_UINT8 PSF; 147 IMG_UINT8 EXTENDED_DMV; 148 149 IMG_UINT8 PANSCAN_FLAG; 150 IMG_UINT8 REFDIST_FLAG; 151 IMG_UINT8 LOOPFILTER; 152 IMG_UINT8 FASTUVMC; 153 IMG_UINT8 EXTENDED_MV; 154 IMG_UINT8 DQUANT; 155 IMG_UINT8 VSTRANSFORM; 156 157 IMG_UINT8 QUANTIZER; 158 IMG_UINT8 MULTIRES; 159 IMG_UINT8 SYNCMARKER; 160 IMG_UINT8 RANGERED; 161 IMG_UINT8 MAXBFRAMES; 162 163 IMG_UINT8 OVERLAP; 164 165 IMG_UINT8 PROFILE; 166 167 } vc1SeqHeader; 168 169 //! Maximum number of VLC tables for MB/block layer decode 170 #define MAX_VLC_TABLES (12) 171 172 typedef struct { // Information about VLC tables 173 IMG_UINT16 aui16StartLocation; //!< Byte offset within the packed VLC tables array 174 IMG_UINT16 aui16VLCTableLength; //!< Length of the table in number of bytes 175 IMG_UINT16 aui16RAMLocation; //!< Location of the VLC table in the destination buffer 176 IMG_UINT16 aui16InitialWidth; 177 IMG_UINT16 aui16InitialOpcode; 178 179 } sTableData; 180 181 typedef struct { // Information about the intensity compensation history of previous pictures 182 IMG_UINT8 ui8LumaScale1; 183 IMG_UINT8 ui8LumaShift1; 184 185 IMG_UINT8 ui8LumaScale2; 186 IMG_UINT8 ui8LumaShift2; 187 188 /* Indication of what fields undergo intensity compensation */ 189 IMG_UINT8 ui8IC1; // 1 - IC top field, 2 - IC bottom field, 3 - IC both fields 190 IMG_UINT8 ui8IC2; 191 192 } IC_PARAM; 193 194 195 #define VLC_INDEX_TABLE_SIZE 83 196 197 struct context_VC1_s { 198 struct context_DEC_s dec_ctx; 199 object_context_p obj_context; /* back reference */ 200 201 uint32_t profile; 202 203 /* Picture parameters */ 204 VAPictureParameterBufferVC1 *pic_params; 205 object_surface_p forward_ref_surface; 206 object_surface_p backward_ref_surface; 207 object_surface_p decoded_surface; 208 209 uint32_t display_picture_width; /* in pixels */ 210 uint32_t display_picture_height; /* in pixels */ 211 uint32_t coded_picture_width; /* in pixels */ 212 uint32_t coded_picture_height; /* in pixels */ 213 214 uint32_t picture_width_mb; /* in macroblocks */ 215 uint32_t picture_height_mb; /* in macroblocks */ 216 uint32_t size_mb; /* in macroblocks */ 217 218 IMG_BOOL is_first_slice; 219 220 uint32_t scan_index; 221 uint32_t slice_field_type; 222 uint8_t bitplane_present; /* Required bitplanes */ 223 IMG_BOOL has_bitplane; /* Whether a bitplane was passed to the driver */ 224 IMG_BOOL bottom_field; 225 IMG_BOOL half_pel; 226 IMG_BOOL extend_x; 227 IMG_BOOL extend_y; 228 uint8_t mode_config; 229 uint32_t pull_back_x; 230 uint32_t pull_back_y; 231 uint8_t condover; /* Adjusted local version of conditional_overlap_flag */ 232 uint8_t mv_mode; /* Adjusted local version of mv_mode / mv_mode2 */ 233 IMG_BOOL pqindex_gt8; /* Flag to indicate PQINDEX > 8 */ 234 235 /* TODO: 236 LOOPFILTER 237 */ 238 239 240 241 /* 242 CurrPic is the picture currently being decoded. 243 Ref0Pic is the most recent forward reference picture (only used when decoding interlaced field pictures and 244 the reference picture is in the same frame as the current picture). 245 Ref1Pic can either be the most recent forward reference picture (when decoding interlaced frame or 246 progressive pictures) or the 2nd most recent reference picture (when decoding interlaced field pictures). 247 Ref2Pic is the most recent backward reference picture (only used when decoding B pictures). 248 */ 249 IMG_UINT8 ui8FCM_Ref0Pic; /* Used */ 250 IMG_UINT8 ui8FCM_Ref1Pic; /* Used */ 251 IMG_UINT8 ui8FCM_Ref2Pic; /* Used */ 252 253 IMG_BOOL bTFF_FwRefFrm; /* Used */ 254 IMG_BOOL bTFF_BwRefFrm; /* Used */ 255 IMG_BOOL bRef0RangeRed; /* RangeRed flag */ 256 IMG_BOOL bRef1RangeRed; 257 258 IMG_UINT8 ui8IntCompField; /* Used, replace with local var? */ 259 IMG_UINT8 ui8MVmode; /* TODO: Fix, differs slightly from pic_params->mv_mode! */ 260 IMG_INT8 i8FwrdRefFrmDist; /* Used */ 261 IMG_INT8 i8BckwrdRefFrmDist; /* Used */ 262 IMG_UINT32 ui32ScaleFactor; /* Used */ 263 264 /* IC parameters in current picture */ 265 IMG_UINT8 ui8CurrLumaScale1; 266 IMG_UINT8 ui8CurrLumaShift1; 267 IMG_UINT8 ui8CurrLumaScale2; 268 IMG_UINT8 ui8CurrLumaShift2; 269 /* Information about the intensity compensation history of previous pictures */ 270 IC_PARAM sICparams[2][2]; 271 272 273 /* VLC table information */ 274 IMG_UINT32 ui32NumTables; /* VLC table accumulator */ 275 sTableData sTableInfo[MAX_VLC_TABLES]; /* structure of VLC table information */ 276 277 /* Split buffers */ 278 int split_buffer_pending; 279 280 /* List of VASliceParameterBuffers */ 281 object_buffer_p *slice_param_list; 282 int slice_param_list_size; 283 int slice_param_list_idx; 284 285 /* VLC packed data */ 286 struct psb_buffer_s vlc_packed_table; 287 uint32_t vlc_packed_index_table[VLC_INDEX_TABLE_SIZE]; 288 289 /* Preload buffer */ 290 struct psb_buffer_s preload_buffer; 291 292 /* CoLocated buffers */ 293 struct psb_buffer_s *colocated_buffers; 294 int colocated_buffers_size; 295 int colocated_buffers_idx; 296 297 /* Aux MSB buffer */ 298 struct psb_buffer_s aux_msb_buffer; 299 struct psb_buffer_s aux_line_buffer; 300 psb_buffer_p bitplane_buffer; 301 struct psb_buffer_s bitplane_hw_buffer; /* For hw parase */ 302 303 uint32_t *p_range_mapping_base; /* pointer to ui32RangeMappingBase in CMD_HEADER_VC1 */ 304 uint32_t *p_range_mapping_base1; 305 uint32_t *p_slice_params; /* pointer to ui32SliceParams in CMD_HEADER_VC1 */ 306 uint32_t *slice_first_pic_last; 307 uint32_t *alt_output_flags; 308 309 uint32_t forward_ref_fcm; 310 uint32_t backward_ref_fcm; 311 }; 312 313 typedef struct context_VC1_s *context_VC1_p; 314 315 /* VC1 Sequence Header Data Bit Positions Within 32 bit Command Word */ 316 #define VC1_SEQHDR_EXTENDED_DMV 0 317 #define VC1_SEQHDR_PSF 1 318 #define VC1_SEQHDR_SECONDFIELD 2 319 #define VC1_SEQHDR_FINTERPFLAG 3 320 #define VC1_SEQHDR_TFCNTRFLAG 4 321 #define VC1_SEQHDR_INTERLACE 5 322 #define VC1_SEQHDR_PULLDOWN 6 323 #define VC1_SEQHDR_POSTPROCFLAG 7 324 #define VC1_SEQHDR_VSTRANSFORM 8 325 #define VC1_SEQHDR_DQUANT 9 326 #define VC1_SEQHDR_EXTENDED_MV 11 327 #define VC1_SEQHDR_FASTUVMC 12 328 #define VC1_SEQHDR_LOOPFILTER 13 329 #define VC1_SEQHDR_REFDIST_FLAG 14 330 #define VC1_SEQHDR_PANSCAN_FLAG 15 331 #define VC1_SEQHDR_MAXBFRAMES 16 332 #define VC1_SEQHDR_RANGERED 19 333 #define VC1_SEQHDR_SYNCMARKER 20 334 #define VC1_SEQHDR_MULTIRES 21 335 #define VC1_SEQHDR_QUANTIZER 22 336 #define VC1_SEQHDR_OVERLAP 24 337 #define VC1_SEQHDR_PROFILE 25 338 #define VC1_SEQHDR_PICTYPE 27 339 #define VC1_SEQHDR_ICFLAG 29 340 #define VC1_SEQHDR_FCM_CURRPIC 30 341 342 343 #if 0 344 /****************************************************************************************/ 345 /* Local Context */ 346 /****************************************************************************************/ 347 348 typedef struct { 349 VA_CONTEXT sVAContext; /* Must be the first Item */ 350 351 const char *pszHandleType; 352 353 VA_PictureParameters sPicParamVC1; 354 vc1PicHeader sPicHdr; 355 vc1SeqHeader sSeqHdr; 356 357 VA_SliceInfo *pSliceCtrl; 358 PVRSRV_CLIENT_MEM_INFO *psAuxMSBBuffer; 359 PVRSRV_CLIENT_MEM_INFO *hVlcPackedTableData; 360 PVRSRV_CLIENT_MEM_INFO *psCoLocatedData; 361 PVRSRV_CLIENT_MEM_INFO *psPreloadBuffer; 362 363 #if (!VC1_INTERLEAVED_BITPLANE || VC1_BITPLANE_HARDWARE) 364 PVRSRV_CLIENT_MEM_INFO *hBitplaneData[3]; 365 IMG_UINT8 *pui8BitplaneData[3]; 366 #else 367 PVRSRV_CLIENT_MEM_INFO *hBitplaneData; 368 IMG_UINT8 *pui8BitplaneData; 369 #endif 370 #ifdef VC1_LLDMA 371 CMD_BUFFER sCmdBuff; 372 #else 373 PVRSRV_CLIENT_MEM_INFO *psRenderCommandBuffer; 374 #endif 375 PVRSRV_CLIENT_MEM_INFO *psStatusBuffer; 376 IMG_UINT32 *pui32CmdBuffer; 377 IMG_UINT32 *pui32CmdBufferBase; 378 IMG_UINT32 ui32CoLocatedSlot; 379 380 381 /* Status report */ 382 IMG_BOOL bBetweenBeginAndEnd; 383 IMG_UINT32 ui32StatusWof; 384 IMG_UINT32 ui32StatusRof; 385 IMG_UINT32 ui32DevPhysStatusAddr; 386 387 SGX_DDSURFDATA* psDecodeSurfData; 388 SGX_DDSURFDATA* psDeblockSurfData; 389 SGX_DDSURFDATA* psForwardRefSurfData; 390 SGX_DDSURFDATA* psBackwardRefSurfData; 391 392 393 } VC1VLDContext; 394 #endif 395 396 /* 397 ****************************************************************************** 398 Extern global variables 399 ******************************************************************************/ 400 401 extern vc1PicHeader *psPicHdr; 402 extern vc1SeqHeader *psSeqHdr; 403 404 #endif /* _VC1_HEADER_H_ */ 405