Home | History | Annotate | Download | only in va
      1 /*
      2  * Copyright (c) 2014 Intel Corporation. All Rights Reserved.
      3  *
      4  * Permission is hereby granted, free of charge, to any person obtaining a
      5  * copy of this software and associated documentation files (the
      6  * "Software"), to deal in the Software without restriction, including
      7  * without limitation the rights to use, copy, modify, merge, publish,
      8  * distribute, sub license, and/or sell copies of the Software, and to
      9  * permit persons to whom the Software is furnished to do so, subject to
     10  * the following conditions:
     11  *
     12  * The above copyright notice and this permission notice (including the
     13  * next paragraph) shall be included in all copies or substantial portions
     14  * of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
     19  * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR
     20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     23  */
     24 
     25 /**
     26  * \file va_dec_hevc.h
     27  * \brief The HEVC decoding API
     28  *
     29  * This file contains the \ref api_dec_hevc "HEVC decoding API".
     30  */
     31 
     32 #ifndef VA_DEC_HEVC_H
     33 #define VA_DEC_HEVC_H
     34 
     35 #include <stdint.h>
     36 
     37 #ifdef __cplusplus
     38 extern "C" {
     39 #endif
     40 
     41 /**
     42  * \defgroup api_dec_hevc HEVC decoding API
     43  *
     44  * This HEVC decoding API supports Main and Main Still Picture profiles.
     45  * And it supports both short slice format and long slice format.
     46  *
     47  * @{
     48  */
     49 
     50 
     51 
     52 /****************************
     53  * HEVC data structures
     54  ****************************/
     55 
     56 /**
     57  * \brief Description of picture properties of those in DPB surfaces.
     58  *
     59  * If only progressive scan is supported, each surface contains one whole
     60  * frame picture.
     61  * Otherwise, each surface contains two fields of whole picture.
     62  * In this case, two entries of ReferenceFrames[] may share same picture_id
     63  * value.
     64  */
     65 typedef struct _VAPictureHEVC
     66 {
     67     /** \brief reconstructed picture buffer surface index
     68      * invalid when taking value VA_INVALID_SURFACE.
     69      */
     70     VASurfaceID             picture_id;
     71     /** \brief picture order count.
     72      * in HEVC, POCs for top and bottom fields of same picture should
     73      * take different values.
     74      */
     75     int32_t                 PicOrderCnt;
     76     /* described below */
     77     uint32_t                flags;
     78 } VAPictureHEVC;
     79 
     80 /** flags in VAPictureHEVC could be OR of the following */
     81 #define VA_PICTURE_HEVC_INVALID                 0x00000001
     82 /** \brief indication of interlace scan picture.
     83  * should take same value for all the pictures in sequence.
     84  */
     85 #define VA_PICTURE_HEVC_FIELD_PIC               0x00000002
     86 /** \brief polarity of the field picture.
     87  * top field takes even lines of buffer surface.
     88  * bottom field takes odd lines of buffer surface.
     89  */
     90 #define VA_PICTURE_HEVC_BOTTOM_FIELD            0x00000004
     91 /** \brief Long term reference picture */
     92 #define VA_PICTURE_HEVC_LONG_TERM_REFERENCE     0x00000008
     93 /** \brief RefPicSetStCurrBefore of HEVC spec variable
     94  * Number of ReferenceFrames[] entries with this bit set equals
     95  * NumPocStCurrBefore.
     96  */
     97 #define VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE      0x00000010
     98 /** \brief RefPicSetStCurrAfter of HEVC spec variable
     99  * Number of ReferenceFrames[] entries with this bit set equals
    100  * NumPocStCurrAfter.
    101  */
    102 #define VA_PICTURE_HEVC_RPS_ST_CURR_AFTER       0x00000020
    103 /** \brief RefPicSetLtCurr of HEVC spec variable
    104  * Number of ReferenceFrames[] entries with this bit set equals
    105  * NumPocLtCurr.
    106  */
    107 #define VA_PICTURE_HEVC_RPS_LT_CURR             0x00000040
    108 /**
    109  * VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE, VA_PICTURE_HEVC_RPS_ST_CURR_AFTER
    110  * and VA_PICTURE_HEVC_RPS_LT_CURR of any picture in ReferenceFrames[] should
    111  * be exclusive. No more than one of them can be set for any picture.
    112  * Sum of NumPocStCurrBefore, NumPocStCurrAfter and NumPocLtCurr
    113  * equals NumPocTotalCurr, which should be equal to or smaller than 8.
    114  * Application should provide valid values for both short format and long format.
    115  * The pictures in DPB with any of these three flags turned on are referred by
    116  * the current picture.
    117  */
    118 
    119 
    120 
    121 
    122 
    123 /**
    124  * \brief HEVC Decoding Picture Parameter Buffer Structure
    125  *
    126  * This structure conveys picture level parameters and should be sent once
    127  * per frame.
    128  *
    129  */
    130 typedef struct  _VADecPictureParameterBufferHEVC
    131 {
    132     /** \brief buffer description of decoded current picture
    133      * only VA_PICTURE_HEVC_FIELD_PIC and VA_PICTURE_HEVC_BOTTOM_FIELD
    134      * of "flags" fields are meaningful.
    135      */
    136     VAPictureHEVC           CurrPic;
    137     /** \brief buffer description of reference frames in DPB */
    138     VAPictureHEVC           ReferenceFrames[15];
    139     /** \brief picture width, shall be integer multiple of minimum CB size. */
    140     uint16_t                pic_width_in_luma_samples;
    141     /** \brief picture height, shall be integer multiple of minimum CB size. */
    142     uint16_t                pic_height_in_luma_samples;
    143 
    144 
    145     union
    146     {
    147         struct
    148         {
    149         /** following flags have same syntax and semantic as those in HEVC spec */
    150             uint32_t        chroma_format_idc                           : 2;
    151             uint32_t        separate_colour_plane_flag                  : 1;
    152             uint32_t        pcm_enabled_flag                            : 1;
    153             uint32_t        scaling_list_enabled_flag                   : 1;
    154             uint32_t        transform_skip_enabled_flag                 : 1;
    155             uint32_t        amp_enabled_flag                            : 1;
    156             uint32_t        strong_intra_smoothing_enabled_flag         : 1;
    157             uint32_t        sign_data_hiding_enabled_flag               : 1;
    158             uint32_t        constrained_intra_pred_flag                 : 1;
    159             uint32_t        cu_qp_delta_enabled_flag                    : 1;
    160             uint32_t        weighted_pred_flag                          : 1;
    161             uint32_t        weighted_bipred_flag                        : 1;
    162             uint32_t        transquant_bypass_enabled_flag              : 1;
    163             uint32_t        tiles_enabled_flag                          : 1;
    164             uint32_t        entropy_coding_sync_enabled_flag            : 1;
    165             uint32_t        pps_loop_filter_across_slices_enabled_flag  : 1;
    166             uint32_t        loop_filter_across_tiles_enabled_flag       : 1;
    167             uint32_t        pcm_loop_filter_disabled_flag               : 1;
    168             /** set based on sps_max_num_reorder_pics of current temporal layer. */
    169             uint32_t        NoPicReorderingFlag                         : 1;
    170             /** picture has no B slices */
    171             uint32_t        NoBiPredFlag                                : 1;
    172 
    173             uint32_t        ReservedBits                                : 11;
    174         } bits;
    175         uint32_t            value;
    176     } pic_fields;
    177 
    178     /** following parameters have same syntax with those in HEVC spec */
    179     /** \brief DPB size for current temporal layer */
    180     uint8_t                 sps_max_dec_pic_buffering_minus1;
    181     uint8_t                 bit_depth_luma_minus8;
    182     uint8_t                 bit_depth_chroma_minus8;
    183     uint8_t                 pcm_sample_bit_depth_luma_minus1;
    184     uint8_t                 pcm_sample_bit_depth_chroma_minus1;
    185     uint8_t                 log2_min_luma_coding_block_size_minus3;
    186     uint8_t                 log2_diff_max_min_luma_coding_block_size;
    187     uint8_t                 log2_min_transform_block_size_minus2;
    188     uint8_t                 log2_diff_max_min_transform_block_size;
    189     uint8_t                 log2_min_pcm_luma_coding_block_size_minus3;
    190     uint8_t                 log2_diff_max_min_pcm_luma_coding_block_size;
    191     uint8_t                 max_transform_hierarchy_depth_intra;
    192     uint8_t                 max_transform_hierarchy_depth_inter;
    193     int8_t                  init_qp_minus26;
    194     uint8_t                 diff_cu_qp_delta_depth;
    195     int8_t                  pps_cb_qp_offset;
    196     int8_t                  pps_cr_qp_offset;
    197     uint8_t                 log2_parallel_merge_level_minus2;
    198     uint8_t                 num_tile_columns_minus1;
    199     uint8_t                 num_tile_rows_minus1;
    200     /**
    201      * when uniform_spacing_flag equals 1, application should populate
    202      * column_width_minus[], and row_height_minus1[] with approperiate values.
    203      */
    204     uint16_t                column_width_minus1[19];
    205     uint16_t                row_height_minus1[21];
    206 
    207     /**
    208      *  The Following Parameters are needed for Short Slice Format Only.
    209      *  Only format decoding can ignore them.
    210      */
    211 
    212     /**
    213      * \brief Parameters needed for parsing slice segment headers
    214      */
    215     union
    216     {
    217         struct
    218         {
    219             /** following parameters have same syntax with those in HEVC spec */
    220             uint32_t        lists_modification_present_flag             : 1;
    221             uint32_t        long_term_ref_pics_present_flag             : 1;
    222             uint32_t        sps_temporal_mvp_enabled_flag               : 1;
    223             uint32_t        cabac_init_present_flag                     : 1;
    224             uint32_t        output_flag_present_flag                    : 1;
    225             uint32_t        dependent_slice_segments_enabled_flag       : 1;
    226             uint32_t        pps_slice_chroma_qp_offsets_present_flag    : 1;
    227             uint32_t        sample_adaptive_offset_enabled_flag         : 1;
    228             uint32_t        deblocking_filter_override_enabled_flag     : 1;
    229             uint32_t        pps_disable_deblocking_filter_flag          : 1;
    230             uint32_t        slice_segment_header_extension_present_flag : 1;
    231 
    232             /** current picture with NUT between 16 and 21 inclusive */
    233             uint32_t        RapPicFlag                                  : 1;
    234             /** current picture with NUT between 19 and 20 inclusive */
    235             uint32_t        IdrPicFlag                                  : 1;
    236             /** current picture has only intra slices */
    237             uint32_t        IntraPicFlag                                : 1;
    238 
    239             uint32_t        ReservedBits                                : 18;
    240         } bits;
    241         uint32_t            value;
    242     } slice_parsing_fields;
    243 
    244     /** following parameters have same syntax with those in HEVC spec */
    245     uint8_t                 log2_max_pic_order_cnt_lsb_minus4;
    246     uint8_t                 num_short_term_ref_pic_sets;
    247     uint8_t                 num_long_term_ref_pic_sps;
    248     uint8_t                 num_ref_idx_l0_default_active_minus1;
    249     uint8_t                 num_ref_idx_l1_default_active_minus1;
    250     int8_t                  pps_beta_offset_div2;
    251     int8_t                  pps_tc_offset_div2;
    252     uint8_t                 num_extra_slice_header_bits;
    253 
    254     /**
    255      * \brief number of bits that structure
    256      * short_term_ref_pic_set( num_short_term_ref_pic_sets ) takes in slice
    257      * segment header when short_term_ref_pic_set_sps_flag equals 0.
    258      * if short_term_ref_pic_set_sps_flag equals 1, the value should be 0.
    259      * the bit count is calculated after emulation prevention bytes are removed
    260      * from bit streams.
    261      * This variable is used for accelorater to skip parsing the
    262      * short_term_ref_pic_set( num_short_term_ref_pic_sets ) structure.
    263      */
    264     uint32_t                st_rps_bits;
    265 
    266 } VADecPictureParameterBufferHEVC;
    267 
    268 
    269 
    270 /**
    271  * \brief HEVC Slice Parameter Buffer Structure For Short Format
    272  *
    273  * VASliceParameterBufferBaseHEVC structure should be accompanied by a
    274  * slice data buffer, which holds the whole raw slice NAL unit bit streams
    275  * including start code prefix and emulation prevention bytes not removed.
    276  *
    277  * This structure conveys parameters related to slice segment header and should
    278  * be sent once per slice.
    279  *
    280  * For long format, this data structure is not sent by application.
    281  *
    282  */
    283 typedef struct  _VASliceParameterBufferBaseHEVC
    284 {
    285     /** @name Codec-independent Slice Parameter Buffer base. */
    286 
    287     /**@{*/
    288 
    289     /** \brief Number of bytes in the slice data buffer for this slice
    290      *  counting from and including NAL unit header.
    291      */
    292     uint32_t                slice_data_size;
    293     /** \brief The offset to the NAL unit header for this slice */
    294     uint32_t                slice_data_offset;
    295     /** \brief Slice data buffer flags. See \c VA_SLICE_DATA_FLAG_XXX. */
    296     uint16_t                slice_data_flag;
    297     /**@}*/
    298 
    299 } VASliceParameterBufferBaseHEVC;
    300 
    301 
    302 
    303 
    304 /**
    305  * \brief HEVC Slice Parameter Buffer Structure For Long Format
    306  *
    307  * VASliceParameterBufferHEVC structure should be accompanied by a
    308  * slice data buffer, which holds the whole raw slice NAL unit bit streams
    309  * including start code prefix and emulation prevention bytes not removed.
    310  *
    311  * This structure conveys parameters related to slice segment header and should
    312  * be sent once per slice.
    313  *
    314  * For short format, this data structure is not sent by application.
    315  *
    316  */
    317 typedef struct  _VASliceParameterBufferHEVC
    318 {
    319     /** @name Codec-independent Slice Parameter Buffer base. */
    320 
    321     /**@{*/
    322 
    323     /** \brief Number of bytes in the slice data buffer for this slice
    324      * counting from and including NAL unit header.
    325      */
    326     uint32_t                slice_data_size;
    327     /** \brief The offset to the NAL unit header for this slice */
    328     uint32_t                slice_data_offset;
    329     /** \brief Slice data buffer flags. See \c VA_SLICE_DATA_FLAG_XXX. */
    330     uint16_t                slice_data_flag;
    331     /**
    332      * \brief Byte offset from NAL unit header to the begining of slice_data().
    333      *
    334      * This byte offset is relative to and includes the NAL unit header
    335      * and represents the number of bytes parsed in the slice_header()
    336      * after the removal of any emulation prevention bytes in
    337      * there. However, the slice data buffer passed to the hardware is
    338      * the original bitstream, thus including any emulation prevention
    339      * bytes.
    340      * The slice bit stream may or may not include the start code prefix.
    341      */
    342     uint32_t                slice_data_byte_offset;
    343     /** HEVC syntax element. */
    344     uint32_t                slice_segment_address;
    345     /** \brief index into ReferenceFrames[]
    346      * RefPicList[0][] corresponds to RefPicList0[] of HEVC variable.
    347      * RefPicList[1][] corresponds to RefPicList1[] of HEVC variable.
    348      * value range [0..14, 0xFF], where 0xFF indicates invalid entry.
    349      */
    350     uint8_t                 RefPicList[2][15];
    351     union
    352     {
    353         uint32_t            value;
    354         struct
    355         {
    356             /** current slice is last slice of picture. */
    357             uint32_t        LastSliceOfPic                              : 1;
    358     /** HEVC syntax element. */
    359             uint32_t        dependent_slice_segment_flag                : 1;
    360     /** HEVC syntax element. */
    361             uint32_t        slice_type                                  : 2;
    362     /** HEVC syntax element. */
    363             uint32_t        color_plane_id                              : 2;
    364     /** HEVC syntax element. */
    365             uint32_t        slice_sao_luma_flag                         : 1;
    366     /** HEVC syntax element. */
    367             uint32_t        slice_sao_chroma_flag                       : 1;
    368     /** HEVC syntax element. */
    369             uint32_t        mvd_l1_zero_flag                            : 1;
    370     /** HEVC syntax element. */
    371             uint32_t        cabac_init_flag                             : 1;
    372     /** HEVC syntax element. */
    373             uint32_t        slice_temporal_mvp_enabled_flag             : 1;
    374     /** HEVC syntax element. */
    375             uint32_t        slice_deblocking_filter_disabled_flag       : 1;
    376     /** HEVC syntax element. */
    377             uint32_t        collocated_from_l0_flag                     : 1;
    378     /** HEVC syntax element. */
    379             uint32_t        slice_loop_filter_across_slices_enabled_flag : 1;
    380             uint32_t        reserved                                    : 18;
    381         } fields;
    382     } LongSliceFlags;
    383 
    384     /** HEVC syntax element. Collocated Reference Picture Index.
    385      * index to RefPicList[0][] or RefPicList[1][].
    386      * when slice_temporal_mvp_enabled_flag equals 0, it should take value 0xFF.
    387      * value range [0..14, 0xFF].
    388      */
    389     uint8_t                 collocated_ref_idx;
    390     /** HEVC syntax element.
    391      * if num_ref_idx_active_override_flag equals 0, host decoder should
    392      * set its value to num_ref_idx_l0_default_minus1.
    393      */
    394     uint8_t                 num_ref_idx_l0_active_minus1;
    395     /** HEVC syntax element.
    396      * if num_ref_idx_active_override_flag equals 0, host decoder should
    397      * set its value to num_ref_idx_l1_default_minus1.
    398      */
    399     uint8_t                 num_ref_idx_l1_active_minus1;
    400     /** HEVC syntax element. */
    401     int8_t                  slice_qp_delta;
    402     /** HEVC syntax element. */
    403     int8_t                  slice_cb_qp_offset;
    404     /** HEVC syntax element. */
    405     int8_t                  slice_cr_qp_offset;
    406     /** HEVC syntax element. */
    407     int8_t                  slice_beta_offset_div2;
    408     /** HEVC syntax element. */
    409     int8_t                  slice_tc_offset_div2;
    410     /** HEVC syntax element. */
    411     uint8_t                 luma_log2_weight_denom;
    412     /** HEVC syntax element. */
    413     uint8_t                 delta_chroma_log2_weight_denom;
    414     /** HEVC syntax element. */
    415     int8_t                  delta_luma_weight_l0[15];
    416     /** HEVC syntax element. */
    417     int8_t                  luma_offset_l0[15];
    418     /** HEVC syntax element. */
    419     int8_t                  delta_chroma_weight_l0[15][2];
    420     /** corresponds to HEVC spec variable of the same name. */
    421     int8_t                  ChromaOffsetL0[15][2];
    422     /** HEVC syntax element. */
    423     int8_t                  delta_luma_weight_l1[15];
    424     /** HEVC syntax element. */
    425     int8_t                  luma_offset_l1[15];
    426     /** HEVC syntax element. */
    427     int8_t                  delta_chroma_weight_l1[15][2];
    428     /** corresponds to HEVC spec variable of the same name. */
    429     int8_t                  ChromaOffsetL1[15][2];
    430     /** HEVC syntax element. */
    431     uint8_t                 five_minus_max_num_merge_cand;
    432     /**@}*/
    433 
    434 } VASliceParameterBufferHEVC;
    435 
    436 
    437 
    438 /**
    439  * \brief HEVC Inverse Quantization Matrix Buffer Structure
    440  *
    441  * This structure is sent once per frame,
    442  * and only when scaling_list_enabled_flag = 1.
    443  * When sps_scaling_list_data_present_flag = 0, app still
    444  * needs to send in this structure with default matrix values.
    445  *
    446  * Matrix entries are in raster scan order which follows HEVC spec.
    447  */
    448 typedef struct _VAIQMatrixBufferHEVC
    449 {
    450     /**
    451      * \brief scaling lists,
    452      * corresponds to same HEVC spec syntax element
    453      * ScalingList[ i ][ MatrixID ][ j ].
    454      *
    455      * \brief 4x4 scaling,
    456      * correspongs i = 0, MatrixID is in the range of 0 to 5,
    457      * inclusive. And j is in the range of 0 to 15, inclusive.
    458      */
    459     uint8_t                 ScalingList4x4[6][16];
    460     /**
    461      * \brief 8x8 scaling,
    462      * correspongs i = 1, MatrixID is in the range of 0 to 5,
    463      * inclusive. And j is in the range of 0 to 63, inclusive.
    464      */
    465     uint8_t                 ScalingList8x8[6][64];
    466     /**
    467      * \brief 16x16 scaling,
    468      * correspongs i = 2, MatrixID is in the range of 0 to 5,
    469      * inclusive. And j is in the range of 0 to 63, inclusive.
    470      */
    471     uint8_t                 ScalingList16x16[6][64];
    472     /**
    473      * \brief 32x32 scaling,
    474      * correspongs i = 3, MatrixID is in the range of 0 to 1,
    475      * inclusive. And j is in the range of 0 to 63, inclusive.
    476      */
    477     uint8_t                 ScalingList32x32[2][64];
    478     /**
    479      * \brief DC values of the 16x16 scaling lists,
    480      * corresponds to HEVC spec syntax
    481      * scaling_list_dc_coef_minus8[ sizeID - 2 ][ matrixID ] + 8
    482      * with sizeID = 2 and matrixID in the range of 0 to 5, inclusive.
    483      */
    484     uint8_t                 ScalingListDC16x16[6];
    485     /**
    486      * \brief DC values of the 32x32 scaling lists,
    487      * corresponds to HEVC spec syntax
    488      * scaling_list_dc_coef_minus8[ sizeID - 2 ][ matrixID ] + 8
    489      * with sizeID = 3 and matrixID in the range of 0 to 1, inclusive.
    490      */
    491     uint8_t                 ScalingListDC32x32[2];
    492 } VAIQMatrixBufferHEVC;
    493 
    494 
    495 /**@}*/
    496 
    497 #ifdef __cplusplus
    498 }
    499 #endif
    500 
    501 #endif /* VA_DEC_HEVC_H */
    502