Home | History | Annotate | Download | only in mrst
      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  *    Zeng Li <zeng.li (at) intel.com>
     27  *    Shengquan Yuan  <shengquan.yuan (at) intel.com>
     28  *    Binglin Chen <binglin.chen (at) intel.com>
     29  *
     30  */
     31 
     32 
     33 /*
     34  * Description  DMA code for mtx Platform     : Generic
     35  */
     36 
     37 #ifndef _LNC_HOSTHEADER_H_
     38 #define _LNC_HOSTHEADER_H_
     39 
     40 
     41 #include "img_types.h"
     42 
     43 /* Structure contains QP parameters, used with the DoHeader() routine */
     44 typedef struct {
     45     IMG_UINT32 H264_QP;
     46     IMG_UINT32 H263_MPG4_FrameQ_scale;
     47     IMG_UINT32 H263_MPG4_SliceQ_scale;
     48 } MTX_QP_INFO;
     49 
     50 /* #include "topaz_vlc_regs.h" */
     51 
     52 /* Allocating 32 words (128 bytes aligned to 8 bytes) */
     53 #define MAX_HEADERSIZEWORDS (32)
     54 
     55 typedef enum {
     56     ELEMENT_STARTCODE_RAWDATA = 0,/* Rawdata that includes a start code */
     57     ELEMENT_RAWDATA,            /* Rawdata */
     58     ELEMENT_QP,                 /* Insert the H264 Picture Header QP parameter (no rawdata) */
     59     ELEMENT_SQP,                /* Insert the H264 Slice Header QP parameter (no rawdata) */
     60     ELEMENT_FRAMEQSCALE,        /* Insert the H263/MPEG4 Frame Q_scale parameter (vob_quant field) (no rawdata) */
     61     ELEMENT_SLICEQSCALE,        /* Insert the H263/MPEG4 Slice Q_scale parameter (quant_scale field) (no rawdata) */
     62     ELEMENT_INSERTBYTEALIGN_H264,/* Insert the byte align field (no rawdata) */
     63     ELEMENT_INSERTBYTEALIGN_MPG4 /* Insert the byte align field  (no rawdata) */
     64 } HEADER_ELEMENT_TYPE;
     65 
     66 
     67 typedef struct _MTX_HEADER_ELEMENT_ {
     68     HEADER_ELEMENT_TYPE Element_Type;
     69     IMG_UINT8 Size;
     70     IMG_UINT8 Bits;
     71 } MTX_HEADER_ELEMENT;
     72 
     73 
     74 typedef struct _MTX_HEADER_PARAMS_ {
     75     IMG_UINT32 Elements;
     76     MTX_HEADER_ELEMENT asElementStream[MAX_HEADERSIZEWORDS-1];
     77 } MTX_HEADER_PARAMS;
     78 
     79 #define ELEMENTS_EMPTY 9999
     80 
     81 /* H264 Structures
     82  */
     83 
     84 /* Define some constants for the variable elements in the header stream */
     85 typedef enum _SHPROFILES {
     86     SH_PROFILE_BP = 0,
     87     SH_PROFILE_MP = 1
     88 } SH_PROFILE_TYPE;
     89 
     90 /* Level number definitions (integer level numbers, non-intermediary only.. except level 1b) */
     91 typedef enum _SHLEVELS {
     92     SH_LEVEL_1 = 10,
     93     SH_LEVEL_1B = 111,
     94     SH_LEVEL_11 = 11,
     95     SH_LEVEL_12 = 12,
     96     SH_LEVEL_2 = 20,
     97     SH_LEVEL_3 = 30,
     98     SH_LEVEL_31 = 31,
     99     SH_LEVEL_32 = 32,
    100     SH_LEVEL_4 = 40,
    101     SH_LEVEL_5 = 50
    102 } SH_LEVEL_TYPE;
    103 
    104 
    105 typedef enum _SLHP_SLICEFRAME_TYPE_ {
    106     SLHP_P_SLICEFRAME_TYPE,
    107     SLHP_B_SLICEFRAME_TYPE,
    108     SLHP_I_SLICEFRAME_TYPE,
    109     SLHP_SP_SLICEFRAME_TYPE,
    110     SLHP_SI_SLICEFRAME_TYPE,
    111 
    112     SLHP_IDR_SLICEFRAME_TYPE
    113 
    114 } SLHP_SLICEFRAME_TYPE;
    115 
    116 
    117 /* Input parameters for the header generation
    118  * Some of the following data structures may have fields that are actually static..
    119  * may want to prune them down a bit later.
    120  */
    121 typedef struct _H264_VUI_PARAMS_STRUC {
    122     IMG_UINT32 Time_Scale;
    123     IMG_UINT32 bit_rate_value_minus1; /* bitrate/64)-1 */
    124     IMG_UINT32 cbp_size_value_minus1; /* (bitrate*1.5)/16 */
    125     IMG_UINT8 CBR;
    126     IMG_UINT8 initial_cpb_removal_delay_length_minus1;
    127     IMG_UINT8 cpb_removal_delay_length_minus1;
    128     IMG_UINT8 dpb_output_delay_length_minus1;
    129     IMG_UINT8 time_offset_length;
    130 } H264_VUI_PARAMS;
    131 
    132 typedef struct _H264_CROP_PARAMS_STRUCT_ {
    133     IMG_BOOL bClip;
    134     IMG_UINT16 LeftCropOffset;
    135     IMG_UINT16 RightCropOffset;
    136     IMG_UINT16 TopCropOffset;
    137     IMG_UINT16 BottomCropOffset;
    138 } H264_CROP_PARAMS;
    139 
    140 typedef struct _H264_SEQUENCE_HEADER_PARAMS_STRUC {
    141     SH_PROFILE_TYPE ucProfile;
    142     SH_LEVEL_TYPE ucLevel;
    143     IMG_UINT8 ucMax_num_ref_frames;
    144     IMG_UINT8 ucWidth_in_mbs_minus1;
    145     IMG_UINT8 ucHeight_in_maps_units_minus1;
    146     IMG_UINT8 VUI_Params_Present;
    147     H264_VUI_PARAMS VUI_Params;
    148 } H264_SEQUENCE_HEADER_PARAMS;
    149 
    150 
    151 typedef struct _H264_SLICE_HEADER_PARAMS_STRUC {
    152     IMG_UINT8 Start_Code_Prefix_Size_Bytes;
    153     SLHP_SLICEFRAME_TYPE SliceFrame_Type;
    154     IMG_UINT32 First_MB_Address;
    155     IMG_UINT8 Frame_Num_DO;
    156     IMG_UINT8 Picture_Num_DO;
    157     IMG_BOOL bUsesLongTermRef;
    158     IMG_BOOL bIsLongTermRef;
    159     IMG_UINT8 Disable_Deblocking_Filter_Idc;
    160 } H264_SLICE_HEADER_PARAMS;
    161 
    162 
    163 
    164 /* MPEG4 Structures
    165  */
    166 typedef enum _MPEG4_PROFILE {
    167     SP = 1,
    168     ASP = 3
    169 } MPEG4_PROFILE_TYPE;
    170 
    171 typedef enum _FIXED_VOP_TIME_ENUM {
    172     _30FPS = 1,
    173     _15FPS = 2,
    174     _10FPS = 3
    175 } FIXED_VOP_TIME_TYPE;
    176 
    177 typedef struct _VBVPARAMS_STRUC {
    178     IMG_UINT32  First_half_bit_rate;
    179     IMG_UINT32  Latter_half_bit_rate;
    180     IMG_UINT32  First_half_vbv_buffer_size;
    181     IMG_UINT32  Latter_half_vbv_buffer_size;
    182     IMG_UINT32  First_half_vbv_occupancy;
    183     IMG_UINT32  Latter_half_vbv_occupancy;
    184 } VBVPARAMS;
    185 
    186 
    187 /*
    188  * H263 Structures
    189  */
    190 
    191 typedef enum _VOP_CODING_ENUM {
    192     I_FRAME = 0,
    193     P_FRAME = 1
    194 } VOP_CODING_TYPE, H263_PICTURE_CODING_TYPE;
    195 
    196 typedef enum _SEARCH_RANGE_ENUM {
    197     PLUSMINUS_32 = 2,
    198     PLUSMINUS_64 = 3,
    199     FCODE_EQ_4 = 4
    200 }  SEARCH_RANGE_TYPE;
    201 
    202 typedef enum _H263_SOURCE_FORMAT_ENUM {
    203     _128x96_SubQCIF = 1,
    204     _176x144_QCIF = 2,
    205     _352x288_CIF = 3,
    206     _704x576_4CIF = 4
    207 } H263_SOURCE_FORMAT_TYPE;
    208 
    209 
    210 #define SIZEINBITS(a) (sizeof(a)*8)
    211 
    212 /* H264 header preparation */
    213 void lnc__H264_prepare_sequence_header(
    214     IMG_UINT32 *pHeaderMemory,
    215     IMG_UINT32 uiMaxNumRefFrames,
    216     IMG_UINT32 uiPicWidthInMbs,
    217     IMG_UINT32 uiPicHeightInMbs,
    218     IMG_BOOL VUI_present, H264_VUI_PARAMS *VUI_params,
    219     H264_CROP_PARAMS *psCropParams,
    220     IMG_UINT8 uiLevel,
    221     IMG_UINT8 uiProfile);
    222 
    223 void lnc__H264_prepare_picture_header(IMG_UINT32 *pHeaderMemory);
    224 void lnc__H264_prepare_slice_header(
    225     IMG_UINT32 *pHeaderMemory,
    226     IMG_BOOL    bIntraSlice,
    227     IMG_UINT32 uiDisableDeblockingFilterIDC,
    228     IMG_UINT32 uiFrameNumber,
    229     IMG_UINT32 uiFirst_MB_Address,
    230     IMG_UINT32 uiMBSkipRun,
    231     IMG_UINT32 ui_need_idr,
    232     IMG_BOOL bUsesLongTermRef,
    233     IMG_BOOL bIsLongTermRef,
    234     IMG_UINT16 uiIdrPicId);
    235 
    236 void lnc__H264_prepare_eodofstream_header(IMG_UINT32 *pHeaderMemory);
    237 void lnc__H264_prepare_endofpicture_header(IMG_UINT32 *pHeaderMemory);
    238 void lnc__H264_prepare_endofsequence_header(IMG_UINT32 *pHeaderMemory);
    239 
    240 
    241 /* MPEG4 header preparation */
    242 void lnc__MPEG4_prepare_sequence_header(
    243     IMG_UINT32 *pHeaderMemory,
    244     IMG_BOOL bBFrame,
    245     MPEG4_PROFILE_TYPE sProfile,
    246     IMG_UINT8 Profile_and_level_indication,
    247     FIXED_VOP_TIME_TYPE sFixed_vop_time_increment,
    248     IMG_UINT32 Picture_Width_Pixels,
    249     IMG_UINT32 Picture_Height_Pixels,
    250     IMG_BOOL bVBVPresent,
    251     IMG_UINT32  First_half_bit_rate,
    252     IMG_UINT32  Latter_half_bit_rate,
    253     IMG_UINT32  First_half_vbv_buffer_size,
    254     IMG_UINT32  Latter_half_vbv_buffer_size,
    255     IMG_UINT32  First_half_vbv_occupancy,
    256     IMG_UINT32  Latter_half_vbv_occupancy,
    257     IMG_UINT32 VopTimeResolution);
    258 
    259 void lnc__MPEG4_prepare_vop_header(
    260     IMG_UINT32 *pHeaderMem,
    261     IMG_BOOL bIsVOP_coded,
    262     IMG_UINT32 VOP_time_increment,
    263     IMG_UINT8 sSearch_range,
    264     IMG_UINT8 eVop_Coding_Type,
    265     IMG_UINT32 VopTimeResolution);
    266 
    267 
    268 /* H263 header preparation */
    269 void lnc__H263_prepare_sequence_header(
    270     IMG_UINT32 *pHeaderMem,
    271     IMG_UINT8 Profile_and_level_indication);
    272 
    273 void lnc__H263_prepare_picture_header(
    274     IMG_UINT32 *pHeaderMem,
    275     IMG_UINT8 Temporal_Ref,
    276     H263_PICTURE_CODING_TYPE PictureCodingType,
    277     H263_SOURCE_FORMAT_TYPE SourceFormatType,
    278     IMG_UINT8 FrameRate,
    279     IMG_UINT16 PictureWidth,
    280     IMG_UINT16 PictureHeight,
    281     IMG_UINT8 *OptionalCustomPCF);
    282 
    283 void lnc__H263_prepare_GOBslice_header(
    284     IMG_UINT32 *pHeaderMem,
    285     IMG_UINT8 GOBNumber,
    286     IMG_UINT8 GOBFrameId);
    287 
    288 
    289 #endif /* _LNC_HOSTHEADER_H_ */
    290 
    291 
    292 
    293 
    294