Home | History | Annotate | Download | only in parser
      1 /* ///////////////////////////////////////////////////////////////////////
      2 //
      3 //               INTEL CORPORATION PROPRIETARY INFORMATION
      4 //  This software is supplied under the terms of a license agreement or
      5 //  nondisclosure agreement with Intel Corporation and may not be copied
      6 //  or disclosed except in accordance with the terms of that agreement.
      7 //        Copyright (c) 2008 Intel Corporation. All Rights Reserved.
      8 //
      9 //  Description: Common definitions for parsing VC-1 bitstreams.
     10 //
     11 */
     12 
     13 #ifndef _VC1PARSE_COMMON_DEFS_H_
     14 #define _VC1PARSE_COMMON_DEFS_H_
     15 
     16 #ifdef __cplusplus
     17 extern "C" {
     18 #endif
     19 
     20 #include <stdint.h>
     21 
     22 /** @weakgroup vc1parse_common_defs VC-1 Common Definitions */
     23 /** @ingroup vc1parse_common_defs */
     24 /*@{*/
     25 
     26 /** This defines the maximum number of horizontal macroblocks in a picture. */
     27 #define VC1_WIDTH_MB_MAX         ((2048+15)/16)
     28 
     29 /** This defines the maximum number of vertical macroblocks in a picture. */
     30 #define VC1_HEIGHT_MB_MAX        ((1088+15)/16)
     31 
     32 /** This defines the maximum number of bitplane storage per picture. */
     33 #define VC1_MAX_BITPLANE_CHUNKS   3
     34 
     35 /** This defines the value for an invalid BFRACTION syntax element. */
     36 #define VC1_BFRACTION_INVALID    0
     37 
     38 /** This defines the value for BFRACTION syntax element that defines a BI
     39 picture. */
     40 #define VC1_BFRACTION_BI         9
     41 
     42 /** This enumeration defines the various supported profiles as defined in
     43 PROFILE syntax element. */
     44 enum
     45 {
     46     VC1_PROFILE_SIMPLE,
     47     VC1_PROFILE_MAIN,
     48     VC1_PROFILE_RESERVED,
     49     VC1_PROFILE_ADVANCED
     50 };
     51 
     52 /** This enumeration defines the frame coding mode as defined in FCM syntax
     53 element. */
     54 enum
     55 {
     56     VC1_FCM_PROGRESSIVE,
     57     VC1_FCM_FRAME_INTERLACE = 2,
     58     VC1_FCM_FIELD_INTERLACE = 3
     59 };
     60 
     61 /** This enumeration defines the various bitplane types as defined in IMODE
     62 syntax element. */
     63 enum
     64 {
     65     VC1_BITPLANE_RAW_MODE,
     66     VC1_BITPLANE_NORM2_MODE,
     67     VC1_BITPLANE_DIFF2_MODE,
     68     VC1_BITPLANE_NORM6_MODE,
     69     VC1_BITPLANE_DIFF6_MODE,
     70     VC1_BITPLANE_ROWSKIP_MODE,
     71     VC1_BITPLANE_COLSKIP_MODE
     72 };
     73 
     74 /** This enumeration defines the various motion vector modes as defined in
     75 MVMODE or MVMODE2 syntax element. */
     76 enum
     77 {
     78     VC1_MVMODE_1MV,
     79 #ifdef VBP
     80     VC1_MVMODE_HPELBI_1MV,
     81     VC1_MVMODE_HPEL_1MV,
     82 #else
     83     VC1_MVMODE_HPEL_1MV,
     84     VC1_MVMODE_HPELBI_1MV,
     85 #endif
     86     VC1_MVMODE_MIXED_MV,
     87     VC1_MVMODE_INTENSCOMP
     88 };
     89 
     90 /** This enumeration defines the extended differential motion vector range flag
     91 as defined in DMVRANGE syntax element. */
     92 enum
     93 {
     94     VC1_DMVRANGE_NONE,
     95     VC1_DMVRANGE_HORIZONTAL_RANGE,
     96     VC1_DMVRANGE_VERTICAL_RANGE,
     97     VC1_DMVRANGE_HORIZONTAL_VERTICAL_RANGE
     98 };
     99 
    100 /** This enumeration defines the intensity compensation field as defined in
    101 INTCOMPFIELD syntax element. */
    102 enum
    103 {
    104     VC1_INTCOMP_TOP_FIELD    = 1,
    105     VC1_INTCOMP_BOTTOM_FIELD = 2,
    106     VC1_INTCOMP_BOTH_FIELD   = 3
    107 };
    108 
    109 /** This enumeration defines the differential quantizer profiles as defined in
    110 DQPROFILE syntax element. */
    111 enum
    112 {
    113     VC1_DQPROFILE_ALL4EDGES,
    114     VC1_DQPROFILE_DBLEDGES,
    115     VC1_DQPROFILE_SNGLEDGES,
    116     VC1_DQPROFILE_ALLMBLKS
    117 };
    118 
    119 /** This enumeration defines the conditional overlap flag as defined in CONDOVER
    120 syntax element. */
    121 enum
    122 {
    123     VC1_CONDOVER_FLAG_NONE = 0,
    124     VC1_CONDOVER_FLAG_ALL  = 2,
    125     VC1_CONDOVER_FLAG_SOME = 3
    126 };
    127 
    128 /** This enumeration defines the type of quantizer to be used and is derived
    129 from bitstream syntax. */
    130 enum
    131 {
    132     VC1_QUANTIZER_NONUNIFORM,
    133     VC1_QUANTIZER_UNIFORM
    134 };
    135 
    136 /** This structure represents the various bitplanes within VC-1 bitstream. */
    137 typedef struct
    138 {
    139     uint8_t invert;
    140     int32_t imode;
    141     uint32_t *databits;
    142 } vc1_Bitplane;
    143 
    144 /** This structure represents all bitstream metadata needed for register programming. */
    145 typedef struct
    146 {
    147     // From Sequence Layer for Advanced Profile
    148     uint8_t  PROFILE;                   /**  2 bit(s). */
    149 #ifdef VBP
    150     uint8_t  LEVEL;
    151 #endif
    152     uint8_t  POSTPROCFLAG;              /**  1 bit(s). */
    153     uint8_t  PULLDOWN;                  /**  1 bit(s). */
    154     uint8_t  INTERLACE;                 /**  1 bit(s). */
    155     uint8_t  TFCNTRFLAG;                /**  1 bit(s). */
    156     uint8_t  FINTERPFLAG;               /**  1 bit(s). */
    157     uint8_t  PSF;                       /**  1 bit(s). */
    158     uint8_t  HRD_NUM_LEAKY_BUCKETS;     /**  5 bit(s). */
    159 
    160     // From STRUCT_C
    161     uint8_t  MAXBFRAMES;                /**  3 bit(s). */
    162     uint8_t  MULTIRES;                  /**  1 bit(s). */
    163 
    164     // From EntryPoint Layer for Advanced Profile
    165     uint8_t PANSCAN_FLAG;
    166     uint8_t REFDIST_FLAG;
    167     uint8_t LOOPFILTER;
    168     uint8_t FASTUVMC;
    169     uint8_t EXTENDED_MV;
    170     uint8_t DQUANT;
    171     uint8_t VSTRANSFORM;
    172     uint8_t OVERLAP;
    173     uint8_t QUANTIZER;
    174     uint8_t EXTENDED_DMV;
    175     uint8_t RANGE_MAPY_FLAG;
    176     uint8_t RANGE_MAPY;
    177     uint8_t RANGE_MAPUV_FLAG;
    178     uint8_t RANGE_MAPUV;
    179 
    180     // From Picture Header
    181     uint8_t  RANGERED;                  /**  1 bit(s). */
    182     uint8_t  RNDCTRL;                   /**  1 bit(s), rcv specific. */
    183 
    184     // REFDIST is present only in field-interlaced mode on I/I, I/P, P/I, P/P frames
    185     // From Canmore, looks like this needs to be propagated to following B frames
    186     uint8_t  REFDIST;
    187     uint8_t  INTCOMPFIELD;              /**  ? bit(s)? */
    188     uint8_t  LUMSCALE2;                 /**  6 bit(s). */
    189     uint8_t  LUMSHIFT2;                 /**  6 bit(s). */
    190     uint8_t bp_raw[VC1_MAX_BITPLANE_CHUNKS];
    191 
    192     // From SequenceLayerHeader, EntryPointHeader or Struct_A
    193     uint16_t width;
    194     uint16_t height;
    195     uint16_t widthMB;
    196     uint16_t heightMB;
    197 
    198 #ifdef VBP
    199     uint8_t CLOSED_ENTRY;
    200     uint8_t BROKEN_LINK;
    201     uint8_t SYNCMARKER;
    202 #endif
    203 
    204 } vc1_metadata_t;
    205 
    206 /** This structure represents the sequence header for advanced profile. */
    207 typedef struct
    208 {
    209     union
    210     {
    211 #ifndef MFDBIGENDIAN
    212         struct
    213         {
    214             unsigned BITRTQ_POSTPROC:5;
    215             unsigned FRMRTQ_POSTPROC:3;
    216             unsigned COLORDIFF_FORMAT:2;
    217             unsigned LEVEL:3;
    218             unsigned PROFILE:2;
    219             unsigned pad:17;
    220         } seq_flags;
    221 #else
    222         struct
    223         {
    224             unsigned pad:17;
    225             unsigned PROFILE:2;
    226             unsigned LEVEL:3;
    227             unsigned COLORDIFF_FORMAT:2;
    228             unsigned FRMRTQ_POSTPROC:3;
    229             unsigned BITRTQ_POSTPROC:5;
    230         } seq_flags;
    231 #endif
    232         uint32_t flags;
    233     };
    234 
    235     union
    236     {
    237 #ifndef MFDBIGENDIAN
    238         struct
    239         {
    240             unsigned DISPLAY_EXT:1;
    241             unsigned PSF:1;
    242             unsigned RESERVED:1;
    243             unsigned FINTERPFLAG:1;
    244             unsigned TFCNTRFLAG:1;
    245             unsigned INTERLACE:1;
    246             unsigned PULLDOWN:1;
    247             unsigned MAX_CODED_HEIGHT:12;
    248             unsigned MAX_CODED_WIDTH:12;
    249             unsigned POSTPROCFLAG:1;
    250         } seq_max_size;
    251 #else
    252         struct
    253         {
    254             unsigned POSTPROCFLAG:1;
    255             unsigned MAX_CODED_WIDTH:12;
    256             unsigned MAX_CODED_HEIGHT:12;
    257             unsigned PULLDOWN:1;
    258             unsigned INTERLACE:1;
    259             unsigned TFCNTRFLAG:1;
    260             unsigned FINTERPFLAG:1;
    261             unsigned RESERVED:1;
    262             unsigned PSF:1;
    263             unsigned DISPLAY_EXT:1;
    264         } seq_max_size;
    265 #endif
    266         uint32_t max_size;
    267     };
    268 
    269     union
    270     {
    271 #ifndef MFDBIGENDIAN
    272         struct
    273         {
    274             unsigned ASPECT_RATIO_FLAG:1;
    275             unsigned DISP_VERT_SIZE:14;
    276             unsigned DISP_HORIZ_SIZE:14;
    277             unsigned pad:3;
    278         } seq_disp_size;
    279 #else
    280         struct
    281         {
    282             unsigned pad:3;
    283             unsigned DISP_HORIZ_SIZE:14;
    284             unsigned DISP_VERT_SIZE:14;
    285             unsigned ASPECT_RATIO_FLAG:1;
    286         } seq_disp_size;
    287 #endif
    288         uint32_t disp_size;
    289     };
    290 
    291     uint8_t ASPECT_RATIO;   // 4 bits
    292 
    293     union
    294     {
    295 #ifndef MFDBIGENDIAN
    296         struct
    297         {
    298             unsigned ASPECT_VERT_SIZE:8;
    299             unsigned ASPECT_HORIZ_SIZE:8;
    300             unsigned pad:16;
    301         } seq_aspect_size;
    302 #else
    303         struct
    304         {
    305             unsigned pad:16;
    306             unsigned ASPECT_HORIZ_SIZE:8;
    307             unsigned ASPECT_VERT_SIZE:8;
    308         } seq_aspect_size;
    309 #endif
    310         uint32_t aspect_size;
    311     };
    312 
    313     uint8_t FRAMERATE_FLAG; // 1b
    314     uint8_t FRAMERATEIND;   // 1b
    315 
    316     union
    317     {
    318 #ifndef MFDBIGENDIAN
    319         struct
    320         {
    321             unsigned FRAMERATEDR:4;
    322             unsigned FRAMERATENR:8;
    323             unsigned pad:20;
    324         } seq_framerate_fraction;
    325 #else
    326         struct
    327         {
    328             unsigned pad:20;
    329             unsigned FRAMERATENR:8;
    330             unsigned FRAMERATEDR:4;
    331         } seq_framerate_fraction;
    332 #endif
    333         uint32_t framerate_fraction;
    334     };
    335 
    336     uint16_t FRAMERATEEXP;      // 16b
    337     uint8_t COLOR_FORMAT_FLAG; // 1b
    338 
    339     union
    340     {
    341 #ifndef MFDBIGENDIAN
    342         struct
    343         {
    344             unsigned MATRIX_COEF:8;
    345             unsigned TRANSFER_CHAR:8;
    346             unsigned COLOR_PRIM:8;
    347             unsigned pad:8;
    348         } seq_color_format;
    349 #else
    350         struct
    351         {
    352             unsigned pad:8;
    353             unsigned COLOR_PRIM:8;
    354             unsigned TRANSFER_CHAR:8;
    355             unsigned MATRIX_COEF:8;
    356         } seq_color_format;
    357 #endif
    358         uint32_t color_format;
    359     };
    360 
    361     uint8_t HRD_PARAM_FLAG;         // 1b
    362     uint8_t HRD_NUM_LEAKY_BUCKETS;  // 5b
    363     // No need to parse remaining items - not needed so far
    364 } vc1_SequenceLayerHeader;
    365 
    366 /** This structure represents metadata for struct c. */
    367 typedef struct
    368 {
    369     union
    370     {
    371 #ifndef MFDBIGENDIAN
    372         struct
    373         {
    374             unsigned res6:1;
    375             unsigned FINTERPFLAG:1;
    376             unsigned QUANTIZER:2;
    377             unsigned MAXBFRAMES:3;
    378             unsigned RANGERED:1;
    379             unsigned SYNCMARKER:1;
    380             unsigned OVERLAP:1;
    381             unsigned res5:1;
    382             unsigned VSTRANSFORM:1;
    383             unsigned DQUANT:2;
    384             unsigned EXTENDED_MV:1;
    385             unsigned FASTUVMC:1;
    386             unsigned res4:1;
    387             unsigned MULTIRES:1;
    388             unsigned res3:1;
    389             unsigned LOOPFILTER:1;
    390             unsigned BITRTQ_POSTPROC:5;
    391             unsigned FRMRTQ_POSTPROC:3;
    392             unsigned PROFILE:4;
    393         } struct_c;
    394 #else
    395         struct
    396         {
    397             unsigned PROFILE:4;
    398             unsigned FRMRTQ_POSTPROC:3;
    399             unsigned BITRTQ_POSTPROC:5;
    400             unsigned LOOPFILTER:1;
    401             unsigned res3:1;
    402             unsigned MULTIRES:1;
    403             unsigned res4:1;
    404             unsigned FASTUVMC:1;
    405             unsigned EXTENDED_MV:1;
    406             unsigned DQUANT:2;
    407             unsigned VSTRANSFORM:1;
    408             unsigned res5:1;
    409             unsigned OVERLAP:1;
    410             unsigned SYNCMARKER:1;
    411             unsigned RANGERED:1;
    412             unsigned MAXBFRAMES:3;
    413             unsigned QUANTIZER:2;
    414             unsigned FINTERPFLAG:1;
    415             unsigned res6:1;
    416         } struct_c;
    417 #endif
    418         uint32_t struct_c_rcv;
    419     };
    420 
    421     union
    422     {
    423 #ifndef MFDBIGENDIAN
    424         struct
    425         {
    426             unsigned VERT_SIZE:16;
    427             unsigned HORIZ_SIZE:16;
    428         } struct_a;
    429 #else
    430         struct
    431         {
    432             unsigned HORIZ_SIZE:16;
    433             unsigned VERT_SIZE:16;
    434         } struct_a;
    435 #endif
    436         uint32_t struct_a_rcv;
    437     };
    438 
    439 } vc1_RcvSequenceHeader;
    440 
    441 /** This structure represents metadata for entry point layers. */
    442 typedef struct
    443 {
    444     union
    445     {
    446 #ifndef MFDBIGENDIAN
    447         struct
    448         {
    449             unsigned QUANTIZER:2;
    450             unsigned OVERLAP:1;
    451             unsigned VSTRANSFORM:1;
    452             unsigned DQUANT:2;
    453             unsigned EXTENDED_MV:1;
    454             unsigned FASTUVMC:1;
    455             unsigned LOOPFILTER:1;
    456             unsigned REFDIST_FLAG:1;
    457             unsigned PANSCAN_FLAG:1;
    458             unsigned CLOSED_ENTRY:1;
    459             unsigned BROKEN_LINK:1;
    460             unsigned pad1:19;
    461         } ep_flags;
    462 #else
    463         struct
    464         {
    465             unsigned pad1:19;
    466             unsigned BROKEN_LINK:1;
    467             unsigned CLOSED_ENTRY:1;
    468             unsigned PANSCAN_FLAG:1;
    469             unsigned REFDIST_FLAG:1;
    470             unsigned LOOPFILTER:1;
    471             unsigned FASTUVMC:1;
    472             unsigned EXTENDED_MV:1;
    473             unsigned DQUANT:2;
    474             unsigned VSTRANSFORM:1;
    475             unsigned OVERLAP:1;
    476             unsigned QUANTIZER:2;
    477         } ep_flags;
    478 #endif
    479         uint32_t flags;
    480     };
    481 
    482     // Skipping HRD data because it is not needed for our processing
    483 
    484     union
    485     {
    486 #ifndef MFDBIGENDIAN
    487         struct
    488         {
    489             unsigned CODED_HEIGHT:12;
    490             unsigned CODED_WIDTH:12;
    491             unsigned pad2:8;
    492         } ep_size;
    493 #else
    494         struct
    495         {
    496             unsigned pad2:8;
    497             unsigned CODED_WIDTH:12;
    498             unsigned CODED_HEIGHT:12;
    499         } ep_size;
    500 #endif
    501         uint32_t size;
    502     };
    503 
    504     uint8_t  CODED_SIZE_FLAG;           /**  1 bit(s). */
    505     uint8_t  EXTENDED_DMV;              /**  1 bit(s). */
    506     uint8_t  RANGE_MAPY_FLAG;           /**  1 bit(s). */
    507     uint8_t  RANGE_MAPY;                /**  3 bit(s). */
    508     uint8_t  RANGE_MAPUV_FLAG;          /**  1 bit(s). */
    509     uint8_t  RANGE_MAPUV;               /**  3 bit(s). */
    510 } vc1_EntryPointHeader;
    511 
    512 /** This structure represents metadata for slice and picture layers. */
    513 typedef struct
    514 {
    515     /* Slice layer. */
    516     uint16_t SLICE_ADDR;                /**  9 bit(s). */
    517 
    518     /* Picture layer for simple or main profile. */
    519     uint8_t  RANGEREDFRM;               /**  1 bit(s). */
    520     uint8_t  PTYPE;                     /**  4 bit(s)? */
    521     int8_t   BFRACTION_NUM;             /**  ? bit(s). */
    522     int16_t  BFRACTION_DEN;             /**  ? bit(s). */
    523     uint8_t  PQINDEX;                   /**  5 bit(s). */
    524     uint8_t  HALFQP;                    /**  1 bit(s). */
    525     uint8_t  PQUANTIZER;                /**  1 bit(s). */
    526     uint8_t  MVRANGE;                   /**  3 bit(s)? */
    527     uint8_t  MVMODE;                    /**  4 bit(s)? */
    528     uint8_t  MVMODE2;                   /**  3 bit(s)? */
    529     uint8_t  LUMSCALE;                  /**  6 bit(s). */
    530     uint8_t  LUMSHIFT;                  /**  6 bit(s). */
    531     uint8_t  MVTAB;                     /**  2 bit(s). */
    532     uint8_t  CBPTAB;                    /**  2 bit(s). */
    533     uint8_t  TTMBF;                     /**  1 bit(s). */
    534     uint8_t  TTFRM;                     /**  2 bit(s). */
    535     uint8_t  TRANSACFRM;                /**  2 bit(s)? */
    536     uint8_t  TRANSACFRM2;               /**  2 bit(s)? */
    537     uint8_t  TRANSDCTAB;                /**  1 bit(s). */
    538 
    539     /* Picture layer for advanced profile. */
    540     uint8_t  FCM;                       /**  2 bit(s)? */
    541     uint8_t  FPTYPE;                    /**  3 bit(s). */
    542     uint8_t  TFCNTR;                    /**  8 bit(s) */
    543     uint8_t  RPTFRM;                    /**  2 bit(s) */
    544     uint8_t  TFF;                       /**  1 bit(s). */
    545     uint8_t  RFF;                    	/**  1 bit(s) */
    546     uint8_t  RNDCTRL;                   /**  1 bit(s). */
    547     uint8_t  UVSAMP;                    /**  1 bit(s). */
    548     uint8_t  POSTPROC;                  /**  2 bit(s). */
    549     uint8_t  CONDOVER;                  /**  2 bit(s)? */
    550     uint8_t  DMVRANGE;                  /**  ? bit(s)? */
    551     uint8_t  MV4SWITCH;                 /**  1 bit(s). */
    552     uint8_t  INTCOMP;                   /**  1 bit(s). */
    553     uint8_t  MBMODETAB;                 /**  2 bit(s). */
    554     uint8_t  MV2BPTAB;                  /**  2 bit(s). */
    555     uint8_t  MV4BPTAB;                  /**  2 bit(s). */
    556     uint8_t  NUMREF;                    /**  1 bit(s). */
    557     uint8_t  REFFIELD;                  /**  1 bit(s). */
    558 
    559     /* PAN SCAN */
    560     uint8_t  PS_PRESENT;                /**  1 bit(s). */
    561     uint8_t number_of_pan_scan_window;	/** 4 max. */
    562     viddec_vc1_pan_scan_window_t PAN_SCAN_WINDOW[VIDDEC_PANSCAN_MAX_OFFSETS];
    563 
    564     /* VOPDQUANT. */
    565     uint8_t  PQDIFF;                    /**  3 bit(s). */
    566     uint8_t  ABSPQ;                     /**  5 bit(s). */
    567     uint8_t  DQUANTFRM;                 /**  1 bit(s). */
    568     uint8_t  DQPROFILE;                 /**  2 bit(s). */
    569     uint8_t  DQSBEDGE;                  /**  2 bit(s). */
    570     uint8_t  DQBILEVEL;                 /**  1 bit(s). */
    571 
    572     /* Others. */
    573     uint8_t  PTypeField1;
    574     uint8_t  PTypeField2;
    575     uint32_t PQUANT;
    576     uint8_t  CurrField;
    577     uint8_t  BottomField;
    578     uint32_t UniformQuant;
    579 
    580 #ifdef VBP
    581     uint8_t  raw_MVTYPEMB;
    582     uint8_t  raw_DIRECTMB;
    583     uint8_t  raw_SKIPMB;
    584     uint8_t  raw_ACPRED;
    585     uint8_t  raw_FIELDTX;
    586     uint8_t  raw_OVERFLAGS;
    587     uint8_t  raw_FORWARDMB;
    588 
    589     vc1_Bitplane MVTYPEMB;
    590     vc1_Bitplane DIRECTMB;
    591     vc1_Bitplane SKIPMB;
    592     vc1_Bitplane ACPRED;
    593     vc1_Bitplane FIELDTX;
    594     vc1_Bitplane OVERFLAGS;
    595     vc1_Bitplane FORWARDMB;
    596     uint32_t  ALTPQUANT;
    597     uint8_t		DQDBEDGE;
    598 #endif
    599 
    600 } vc1_PictureLayerHeader;
    601 
    602 /*@}*/
    603 
    604 #ifdef __cplusplus
    605 }
    606 #endif /* __cplusplus. */
    607 
    608 #endif /* _VC1PARSE_COMMON_DEFS_H_. */
    609