Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright 2010 Samsung Electronics Co. LTD
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef _MFC_INTERFACE_H_
     18 #define _MFC_INTERFACE_H_
     19 
     20 #include "SsbSipMfcApi.h"
     21 
     22 #define IOCTL_MFC_DEC_INIT                     0x00800001
     23 #define IOCTL_MFC_ENC_INIT                     0x00800002
     24 #define IOCTL_MFC_DEC_EXE                      0x00800003
     25 #define IOCTL_MFC_ENC_EXE                      0x00800004
     26 
     27 #define IOCTL_MFC_GET_IN_BUF                   0x00800010
     28 #define IOCTL_MFC_FREE_BUF                     0x00800011
     29 #define IOCTL_MFC_GET_PHYS_ADDR                0x00800012
     30 
     31 #define IOCTL_MFC_SET_CONFIG                   0x00800101
     32 #define IOCTL_MFC_GET_CONFIG                   0x00800102
     33 
     34 #define IOCTL_MFC_BUF_CACHE                    0x00801000
     35 
     36 /* MFC H/W support maximum 32 extra DPB */
     37 #define MFC_MAX_EXTRA_DPB                      5
     38 
     39 #define ENC_PROFILE_LEVEL(profile, level)      ((profile) | ((level) << 8))
     40 
     41 #define ENC_PROFILE_MPEG4_SP                   0
     42 #define ENC_PROFILE_MPEG4_ASP                  1
     43 #define ENC_PROFILE_H264_BP                    0
     44 #define ENC_PROFILE_H264_MAIN                  1
     45 #define ENC_PROFILE_H264_HIGH                  2
     46 
     47 #define ENC_RC_DISABLE                         0
     48 #define ENC_RC_ENABLE_MACROBLOCK               1
     49 #define ENC_RC_ENABLE_FRAME                    2
     50 
     51 #define ENC_RC_QBOUND(min_qp, max_qp)          ((min_qp) | ((max_qp) << 8))
     52 #define ENC_RC_MB_CTRL_DARK_DISABLE            (1 << 3)
     53 #define ENC_RC_MB_CTRL_SMOOTH_DISABLE          (1 << 2)
     54 #define ENC_RC_MB_CTRL_STATIC_DISABLE          (1 << 1)
     55 #define ENC_RC_MB_CTRL_ACTIVITY_DISABLE        (1 << 0)
     56 
     57 #define ALIGN_TO_16B(x)   ((((x) + (1 <<  4) - 1) >>  4) <<  4)
     58 #define ALIGN_TO_32B(x)   ((((x) + (1 <<  5) - 1) >>  5) <<  5)
     59 #define ALIGN_TO_64B(x)   ((((x) + (1 <<  6) - 1) >>  6) <<  6)
     60 #define ALIGN_TO_128B(x)  ((((x) + (1 <<  7) - 1) >>  7) <<  7)
     61 #define ALIGN_TO_2KB(x)   ((((x) + (1 << 11) - 1) >> 11) << 11)
     62 #define ALIGN_TO_4KB(x)   ((((x) + (1 << 12) - 1) >> 12) << 12)
     63 #define ALIGN_TO_8KB(x)   ((((x) + (1 << 13) - 1) >> 13) << 13)
     64 #define ALIGN_TO_64KB(x)  ((((x) + (1 << 16) - 1) >> 16) << 16)
     65 #define ALIGN_TO_128KB(x) ((((x) + (1 << 17) - 1) >> 17) << 17)
     66 
     67 typedef struct {
     68     int luma0;    // per frame (or top field)
     69     int chroma0;    // per frame (or top field)
     70     int luma1;    // per frame (or bottom field)
     71     int chroma1;    // per frame (or bottom field)
     72 } MFC_CRC_DATA;
     73 
     74 typedef enum {
     75     MFC_USE_NONE = 0x00,
     76     MFC_USE_YUV_BUFF = 0x01,
     77     MFC_USE_STRM_BUFF = 0x10
     78 } mfc_interbuff_status;
     79 
     80 typedef enum {
     81     MFC_UNPACKED_PB = 0,
     82     MFC_PACKED_PB = 1
     83 } mfc_packed_mode;
     84 
     85 typedef struct tag_strm_ref_buf_arg {
     86     unsigned int strm_ref_y;
     87     unsigned int mv_ref_yc;
     88 } mfc_strm_ref_buf_arg_t;
     89 
     90 typedef struct tag_frame_buf_arg {
     91     unsigned int luma;
     92     unsigned int chroma;
     93 } mfc_frame_buf_arg_t;
     94 
     95 typedef struct {
     96     SSBSIP_MFC_CODEC_TYPE in_codec_type; /* [IN] codec type                                              */
     97     int in_width;                        /* [IN] width of YUV420 frame to be encoded                     */
     98     int in_height;                       /* [IN] height of YUV420 frame to be encoded                    */
     99     int in_profile_level;                /* [IN] profile & level                                         */
    100     int in_gop_num;                      /* [IN] GOP Number (interval of I-frame)                        */
    101     int in_frame_qp;                     /* [IN] the quantization parameter of the frame                 */
    102     int in_frame_P_qp;                   /* [IN] the quantization parameter of the P frame               */
    103     int in_frame_B_qp;                   /* [IN] the quantization parameter of the B frame               */
    104 
    105     int in_RC_frm_enable;                /* [IN] RC enable (0:disable, 1:frame level RC)                 */
    106     int in_RC_framerate;                 /* [IN] RC parameter (framerate)                                */
    107     int in_RC_bitrate;                   /* [IN] RC parameter (bitrate in kbps)                          */
    108     int in_RC_qbound;                    /* [IN] RC parameter (Q bound)                                  */
    109     int in_RC_rpara;                     /* [IN] RC parameter (Reaction Coefficient)                     */
    110 
    111     int in_MS_mode;                      /* [IN] Multi-slice mode (0:single, 1:multiple)                 */
    112     int in_MS_size;                      /* [IN] Multi-slice size (in num. of mb or byte)                */
    113     int in_mb_refresh;                   /* [IN] Macroblock refresh                                      */
    114     int in_interlace_mode;               /* [IN] interlace mode(0:progressive, 1:interlace)              */
    115     int in_BframeNum;                    /* [IN] B frame number                                          */
    116 
    117     int in_pad_ctrl_on;                  /* [IN] Enable (1) / Disable (0) padding                        */
    118     int in_luma_pad_val;                 /* [IN] pad value if pad_ctrl_on is Enable                      */
    119     int in_cb_pad_val;
    120     int in_cr_pad_val;
    121 
    122     int in_frame_map;                    /* [IN] Encoding input NV12 type linear(0) TILE(1)              */
    123 
    124     unsigned int in_mapped_addr;
    125     mfc_strm_ref_buf_arg_t out_u_addr;
    126     mfc_strm_ref_buf_arg_t out_p_addr;
    127     mfc_strm_ref_buf_arg_t out_buf_size;
    128     unsigned int out_header_size;
    129 
    130     /* MPEG4 Only */
    131     int in_qpelME_enable;                /* [IN] Quarter-pel MC enable(1:enable, 0:disable)              */
    132     int in_time_increament_res;          /* [IN] time increment resolution                               */
    133     int in_time_vop_time_increament;     /* [IN] time increment                                          */
    134 } mfc_enc_init_mpeg4_arg_t;
    135 
    136 typedef mfc_enc_init_mpeg4_arg_t mfc_enc_init_h263_arg_t;
    137 
    138 typedef struct {
    139     SSBSIP_MFC_CODEC_TYPE in_codec_type; /* [IN] codec type                                              */
    140     int in_width;                        /* [IN] width  of YUV420 frame to be encoded                    */
    141     int in_height;                       /* [IN] height of YUV420 frame to be encoded                    */
    142     int in_profile_level;                /* [IN] profile & level                                         */
    143     int in_gop_num;                      /* [IN] GOP Number (interval of I-frame)                        */
    144     int in_frame_qp;                     /* [IN] the quantization parameter of the frame                 */
    145     int in_frame_P_qp;                   /* [IN] the quantization parameter of the P frame               */
    146     int in_frame_B_qp;                   /* [IN] the quantization parameter of the B frame               */
    147 
    148     int in_RC_frm_enable;                /* [IN] RC enable (0:disable, 1:frame level RC)                 */
    149     int in_RC_framerate;                 /* [IN]  RC parameter (framerate)                               */
    150     int in_RC_bitrate;                   /* [IN]  RC parameter (bitrate in kbps)                         */
    151     int in_RC_qbound;                    /* [IN]  RC parameter (Q bound)                                 */
    152     int in_RC_rpara;                     /* [IN]  RC parameter (Reaction Coefficient)                    */
    153 
    154     int in_MS_mode;                      /* [IN] Multi-slice mode (0:single, 1:multiple)                 */
    155     int in_MS_size;                      /* [IN] Multi-slice size (in num. of mb or byte)                */
    156     int in_mb_refresh;                   /* [IN] Macroblock refresh                                      */
    157     int in_interlace_mode;               /* [IN] interlace mode(0:progressive, 1:interlace)              */
    158     int in_BframeNum;
    159 
    160     int in_pad_ctrl_on;                  /* [IN] Enable padding control                                  */
    161     int in_luma_pad_val;                 /* [IN] Luma pel value used to fill padding area                */
    162     int in_cb_pad_val;                   /* [IN] CB pel value used to fill padding area                  */
    163     int in_cr_pad_val;                   /* [IN] CR pel value used to fill padding area                  */
    164 
    165     int in_frame_map;                    /* [IN] Encoding input NV12 type linear(0) TILE(1)              */
    166 
    167     unsigned int in_mapped_addr;
    168     mfc_strm_ref_buf_arg_t out_u_addr;
    169     mfc_strm_ref_buf_arg_t out_p_addr;
    170     mfc_strm_ref_buf_arg_t out_buf_size;
    171     unsigned int out_header_size;
    172 
    173     /* H264 Only */
    174     int in_RC_mb_enable;                 /* [IN] RC enable (0:disable, 1:MB level RC)                    */
    175     int in_reference_num;                /* [IN] The number of reference pictures used                   */
    176     int in_ref_num_p;                    /* [IN] The number of reference pictures used for P pictures    */
    177     int in_RC_mb_dark_disable;           /* [IN] Disable adaptive rate control on dark region            */
    178     int in_RC_mb_smooth_disable;         /* [IN] Disable adaptive rate control on smooth region          */
    179     int in_RC_mb_static_disable;         /* [IN] Disable adaptive rate control on static region          */
    180     int in_RC_mb_activity_disable;       /* [IN] Disable adaptive rate control on static region          */
    181     int in_deblock_filt;                 /* [IN] disable the loop filter                                 */
    182     int in_deblock_alpha_C0;             /* [IN] Alpha & C0 offset for H.264 loop filter                 */
    183     int in_deblock_beta;                 /* [IN] Beta offset for H.264 loop filter                       */
    184     int in_symbolmode;                   /* [IN] The mode of entropy coding(CABAC, CAVLC)                */
    185     int in_transform8x8_mode;            /* [IN] Allow 8x8 transform(only for high profile)              */
    186     int in_md_interweight_pps;           /* [IN] Inter weighted parameter for mode decision              */
    187     int in_md_intraweight_pps;           /* [IN] Intra weighted parameter for mode decision              */
    188 } mfc_enc_init_h264_arg_t;
    189 
    190 typedef struct {
    191     SSBSIP_MFC_CODEC_TYPE in_codec_type; /* [IN]  codec type                                             */
    192     unsigned int in_Y_addr;              /* [IN]  In-buffer addr of Y component                          */
    193     unsigned int in_CbCr_addr;           /* [IN]  In-buffer addr of CbCr component                       */
    194     unsigned int in_Y_addr_vir;          /* [IN]  In-buffer addr of Y component                          */
    195     unsigned int in_CbCr_addr_vir;       /* [IN]  In-buffer addr of CbCr component                       */
    196     unsigned int in_strm_st;             /* [IN]  Out-buffer start addr of encoded strm                  */
    197     unsigned int in_strm_end;            /* [IN]  Out-buffer end addr of encoded strm                    */
    198     int in_frametag;                     /* [IN]  unique frame ID                                        */
    199 
    200     unsigned int out_frame_type;         /* [OUT] frame type                                             */
    201     int out_encoded_size;                /* [OUT] Length of Encoded video stream                         */
    202     unsigned int out_encoded_Y_paddr;    /* [OUT] physical Y address which is flushed                    */
    203     unsigned int out_encoded_C_paddr;    /* [OUT] physical C address which is flushed                    */
    204     int out_frametag_top;                /* [OUT] unique frame ID of an output frame or top field        */
    205     int out_frametag_bottom;             /* [OUT] unique frame ID of bottom field                        */
    206 } mfc_enc_exe_arg;
    207 
    208 typedef struct {
    209     SSBSIP_MFC_CODEC_TYPE in_codec_type; /* [IN]  codec type                                             */
    210     unsigned int in_strm_buf;            /* [IN]  the physical address of STRM_BUF                       */
    211     int in_strm_size;                    /* [IN]  size of video stream filled in STRM_BUF                */
    212     int in_packed_PB;                    /* [IN]  Is packed PB frame or not, 1: packedPB  0: unpacked    */
    213 
    214     int out_img_width;                   /* [OUT] width  of YUV420 frame                                 */
    215     int out_img_height;                  /* [OUT] height of YUV420 frame                                 */
    216     int out_buf_width;                   /* [OUT] width  of YUV420 frame                                 */
    217     int out_buf_height;                  /* [OUT] height of YUV420 frame                                 */
    218     int out_dpb_cnt;                     /* [OUT] the number of buffers which is nessary during decoding */
    219 
    220     int out_crop_top_offset;             /* [OUT] crop information, top offset                           */
    221     int out_crop_bottom_offset;          /* [OUT] crop information, bottom offset                        */
    222     int out_crop_left_offset;            /* [OUT] crop information, left offset                          */
    223     int out_crop_right_offset;           /* [OUT] crop information, right offset                         */
    224 
    225     mfc_frame_buf_arg_t in_frm_buf;      /* [IN] the address of dpb FRAME_BUF                            */
    226     mfc_frame_buf_arg_t in_frm_size;     /* [IN] size of dpb FRAME_BUF                                   */
    227     unsigned int in_mapped_addr;
    228 
    229     mfc_frame_buf_arg_t out_u_addr;
    230     mfc_frame_buf_arg_t out_p_addr;
    231     mfc_frame_buf_arg_t out_frame_buf_size;
    232 } mfc_dec_init_arg_t;
    233 
    234 typedef struct {
    235     SSBSIP_MFC_CODEC_TYPE in_codec_type; /* [IN]  codec type                                             */
    236     unsigned int in_strm_buf;            /* [IN]  the physical address of STRM_BUF                       */
    237     int in_strm_size;                    /* [IN]  Size of video stream filled in STRM_BUF                */
    238     mfc_frame_buf_arg_t in_frm_buf;      /* [IN]  the address of dpb FRAME_BUF                           */
    239     mfc_frame_buf_arg_t in_frm_size;     /* [IN]  size of dpb FRAME_BUF                                  */
    240     int in_frametag;                     /* [IN]  unique frame ID                                        */
    241 
    242     unsigned int out_display_Y_addr;     /* [OUT] the physical address of display buf                    */
    243     unsigned int out_display_C_addr;     /* [OUT] the physical address of display buf                    */
    244     int out_display_status;              /* [OUT] whether display frame exist or not.                    */
    245     int out_timestamp_top;               /* [OUT] presentation time of an output frame or top field      */
    246     int out_timestamp_bottom;            /* [OUT] presentation time of bottom field                      */
    247     int out_consume_bytes;               /* [OUT] consumed bytes when decoding finished                  */
    248     int out_frametag_top;                /* [OUT] unique frame ID of an output frame or top field        */
    249     int out_frametag_bottom;             /* [OUT] unique frame ID of bottom field                        */
    250     int out_res_change;                  /* [OUT] whether resolution is changed or not (0, 1, 2)         */
    251     int out_crop_top_offset;             /* [OUT] crop information, top offset                           */
    252     int out_crop_bottom_offset;          /* [OUT] crop information, bottom offset                        */
    253     int out_crop_left_offset;            /* [OUT] crop information, left offset                          */
    254     int out_crop_right_offset;           /* [OUT] crop information, right offset                         */
    255 } mfc_dec_exe_arg_t;
    256 
    257 typedef struct {
    258     int in_config_param;                 /* [IN]  Configurable parameter type                            */
    259     int out_config_value[4];             /* [IN]  Values to get for the configurable parameter.          */
    260 } mfc_get_config_arg_t;
    261 
    262 typedef struct {
    263     int in_config_param;                 /* [IN]  Configurable parameter type                            */
    264     int in_config_value[2];              /* [IN]  Values to be set for the configurable parameter.       */
    265     int out_config_value_old[2];         /* [OUT] Old values of the configurable parameters              */
    266 } mfc_set_config_arg_t;
    267 
    268 typedef struct tag_get_phys_addr_arg
    269 {
    270     unsigned int u_addr;
    271     unsigned int p_addr;
    272 } mfc_get_phys_addr_arg_t;
    273 
    274 typedef struct tag_mem_alloc_arg
    275 {
    276     SSBSIP_MFC_CODEC_TYPE codec_type;
    277     int buff_size;
    278     unsigned int mapped_addr;
    279     unsigned int out_uaddr;
    280     unsigned int out_paddr;
    281 } mfc_mem_alloc_arg_t;
    282 
    283 typedef struct tag_mem_free_arg_t
    284 {
    285     unsigned int u_addr;
    286 } mfc_mem_free_arg_t;
    287 
    288 typedef enum {
    289 	MFC_BUFFER_NO_CACHE = 0,
    290 	MFC_BUFFER_CACHE = 1
    291 } mfc_buffer_type;
    292 
    293 typedef union {
    294     mfc_enc_init_mpeg4_arg_t enc_init_mpeg4;
    295     mfc_enc_init_h263_arg_t enc_init_h263;
    296     mfc_enc_init_h264_arg_t enc_init_h264;
    297     mfc_enc_exe_arg enc_exe;
    298 
    299     mfc_dec_init_arg_t dec_init;
    300     mfc_dec_exe_arg_t dec_exe;
    301 
    302     mfc_get_config_arg_t get_config;
    303     mfc_set_config_arg_t set_config;
    304 
    305     mfc_mem_alloc_arg_t mem_alloc;
    306     mfc_mem_free_arg_t mem_free;
    307     mfc_get_phys_addr_arg_t get_phys_addr;
    308 
    309     mfc_buffer_type buf_type;
    310 } mfc_args;
    311 
    312 typedef struct tag_mfc_args {
    313     SSBSIP_MFC_ERROR_CODE ret_code; /* [OUT] error code */
    314     mfc_args args;
    315 } mfc_common_args;
    316 
    317 typedef struct {
    318     int magic;
    319     int hMFC;
    320     int width;
    321     int height;
    322     int sizeStrmBuf;
    323     mfc_frame_buf_arg_t sizeFrmBuf;
    324     int displayStatus;
    325     int inter_buff_status;
    326     unsigned int virFreeStrmAddr;
    327     unsigned int phyStrmBuf;
    328     unsigned int virStrmBuf;
    329     unsigned int virMvRefYC;
    330     mfc_frame_buf_arg_t phyFrmBuf;
    331     mfc_frame_buf_arg_t virFrmBuf;
    332     unsigned int mapped_addr;
    333     mfc_common_args MfcArg;
    334     SSBSIP_MFC_CODEC_TYPE codec_type;
    335     SSBSIP_MFC_DEC_OUTPUT_INFO decOutInfo;
    336     unsigned int encodedHeaderSize;
    337     int encodedDataSize;
    338     unsigned int encodedframeType;
    339     int in_frametag;
    340     int out_frametag_top;
    341     int out_frametag_bottom;
    342     unsigned int encoded_Y_paddr;
    343     unsigned int encoded_C_paddr;
    344     unsigned int encode_cnt;
    345 } _MFCLIB;
    346 
    347 #endif /* _MFC_INTERFACE_H_ */
    348