Home | History | Annotate | Download | only in encoder
      1 /******************************************************************************
      2  *
      3  * Copyright (C) 2018 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at:
      8  *
      9  * http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  *
     17  *****************************************************************************
     18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
     19 */
     20 /*!
     21 ******************************************************************************
     22 * \file ihevce_me_pass.h
     23 *
     24 * \brief
     25 *    Interfaces to create, control and run the ME module
     26 *
     27 * \date
     28 *    22/10/2012
     29 *
     30 * \author
     31 *    Ittiam
     32 *
     33 ******************************************************************************
     34 */
     35 
     36 #ifndef _IHEVCE_ME_PASS_H_
     37 #define _IHEVCE_ME_PASS_H_
     38 
     39 /*****************************************************************************/
     40 /* Constant Macros                                                           */
     41 /*****************************************************************************/
     42 
     43 /*****************************************************************************/
     44 /* Function Macros                                                           */
     45 /*****************************************************************************/
     46 
     47 /*****************************************************************************/
     48 /* Typedefs                                                                  */
     49 /*****************************************************************************/
     50 
     51 /*****************************************************************************/
     52 /* Enums                                                                     */
     53 /*****************************************************************************/
     54 
     55 /*****************************************************************************/
     56 /* Structure                                                                 */
     57 /*****************************************************************************/
     58 
     59 /*****************************************************************************/
     60 /* Extern Variable Declarations                                              */
     61 /*****************************************************************************/
     62 
     63 /*****************************************************************************/
     64 /* Extern Function Declarations                                              */
     65 /*****************************************************************************/
     66 /*!
     67 ******************************************************************************
     68 * \if Function name : ihevce_me_get_num_mem_recs \endif
     69 *
     70 * \brief
     71 *    Number of memory records are returned for ME module
     72 *
     73 *
     74 * \return
     75 *    Number of memory records
     76 *
     77 * \author
     78 *  Ittiam
     79 *
     80 *****************************************************************************
     81 */
     82 WORD32 ihevce_me_get_num_mem_recs(WORD32 i4_num_me_frm_pllel);
     83 
     84 /*!
     85 ******************************************************************************
     86 * \if Function name : ihevce_me_get_mem_recs \endif
     87 *
     88 * \brief
     89 *    Memory requirements are returned for ME.
     90 *
     91 * \param[in,out]  ps_mem_tab : pointer to memory descriptors table
     92 * \param[in] ps_init_prms : Create time static parameters
     93 *
     94 * \return
     95 *    Number of records
     96 *
     97 * \author
     98 *  Ittiam
     99 *
    100 *****************************************************************************
    101 */
    102 WORD32 ihevce_me_get_mem_recs(
    103     iv_mem_rec_t *ps_mem_tab,
    104     ihevce_static_cfg_params_t *ps_init_prms,
    105     WORD32 i4_num_proc_thrds,
    106     WORD32 i4_mem_space,
    107     WORD32 i4_resolution_id,
    108     WORD32 i4_num_me_frm_pllel);
    109 
    110 /*!
    111 ******************************************************************************
    112 * \if Function name : ihevce_me_init \endif
    113 *
    114 * \brief
    115 *    Intialization for ME context state structure .
    116 *
    117 * \param[in] ps_mem_tab : pointer to memory descriptors table
    118 * \param[in] ps_init_prms : Create time static parameters
    119 * \param[in] pv_osal_handle : Osal handle
    120 *
    121 * \return
    122 *    Handle to the ME context
    123 *
    124 * \author
    125 *  Ittiam
    126 *
    127 *****************************************************************************
    128 */
    129 void *ihevce_me_init(
    130     iv_mem_rec_t *ps_mem_tab,
    131     ihevce_static_cfg_params_t *ps_init_prms,
    132     WORD32 i4_num_proc_thrds,
    133     void *pv_osal_handle,
    134     rc_quant_t *ps_rc_quant_ctxt,
    135     void *pv_tile_params_base,
    136     WORD32 i4_resolution_id,
    137     WORD32 i4_num_me_frm_pllel,
    138     UWORD8 u1_is_popcnt_available);
    139 
    140 /**
    141 *******************************************************************************
    142 * \if Function name : ihevce_me_set_resolution \endif
    143 *
    144 * \brief
    145 *    Sets the resolution for ME state
    146 *
    147 * \par Description:
    148 *    ME requires information of resolution to prime up its layer descriptors
    149 *    and contexts. This API is called whenever a control call from application
    150 *    causes a change of resolution. Has to be called once initially before
    151 *    processing any frame. Again this is just a glue function and calls the
    152 *    actual ME API for the same.
    153 *
    154 * \param[in,out] pv_me_ctxt: Handle to the ME context
    155 * \param[in] n_enc_layers: Number of layers getting encoded
    156 * \param[in] p_wd : Pointer containing widths of each layer getting encoded.
    157 * \param[in] p_ht : Pointer containing heights of each layer getting encoded.
    158 *
    159 * \returns
    160 *  none
    161 *
    162 * \author
    163 *  Ittiam
    164 *
    165 *******************************************************************************
    166 */
    167 void ihevce_me_set_resolution(void *pv_me_ctxt, WORD32 n_enc_layers, WORD32 *p_wd, WORD32 *p_ht);
    168 
    169 /*!
    170 ******************************************************************************
    171 * \if Function name : ihevce_me_frame_init \endif
    172 *
    173 * \brief
    174 *    Frame level ME initialisation function
    175 *
    176 * \par Description:
    177 *    The following pre-conditions exist for this function: a. We have the input
    178 *    pic ready for encode, b. We have the reference list with POC, L0/L1 IDs
    179 *    and ref ptrs ready for this picture and c. ihevce_me_set_resolution has
    180 *    been called atleast once. Once these are supplied, the following are
    181 *    done here: a. Input pyramid creation, b. Updation of ME's internal DPB
    182 *    based on available ref list information
    183 *
    184 * \param[in] pv_ctxt : pointer to ME module
    185 * \param[in] ps_frm_ctb_prms : CTB characteristics parameters
    186 * \param[in] ps_frm_lamda : Frame level Lambda params
    187 * \param[in] num_ref_l0 : Number of reference pics in L0 list
    188 * \param[in] num_ref_l1 : Number of reference pics in L1 list
    189 * \param[in] num_ref_l0_active : Active reference pics in L0 dir for current frame (shall be <= num_ref_l0)
    190 * \param[in] num_ref_l1_active : Active reference pics in L1 dir for current frame (shall be <= num_ref_l1)
    191 * \param[in] pps_rec_list_l0 : List of recon pics in L0 list
    192 * \param[in] pps_rec_list_l1 : List of recon pics in L1 list
    193 * \param[in] ps_enc_lap_inp  : pointer to input yuv buffer (frame buffer)
    194 * \param[in] i4_frm_qp       : current picture QP
    195 *
    196 * \return
    197 *    None
    198 *
    199 * \author
    200 *  Ittiam
    201 *
    202 *****************************************************************************
    203 */
    204 void ihevce_me_frame_init(
    205     void *pv_me_ctxt,
    206     me_enc_rdopt_ctxt_t *ps_cur_out_me_prms,
    207     ihevce_static_cfg_params_t *ps_stat_prms,
    208     frm_ctb_ctxt_t *ps_frm_ctb_prms,
    209     frm_lambda_ctxt_t *ps_frm_lamda,
    210     WORD32 num_ref_l0,
    211     WORD32 num_ref_l1,
    212     WORD32 num_ref_l0_active,
    213     WORD32 num_ref_l1_active,
    214     recon_pic_buf_t **pps_rec_list_l0,
    215     recon_pic_buf_t **pps_rec_list_l1,
    216     recon_pic_buf_t *(*aps_ref_list)[HEVCE_MAX_REF_PICS * 2],
    217     func_selector_t *ps_func_selector,
    218     ihevce_lap_enc_buf_t *ps_enc_lap_inp,
    219     void *pv_coarse_layer,
    220     WORD32 i4_me_frm_id,
    221     WORD32 i4_thrd_id,
    222     WORD32 i4_frm_qp,
    223     WORD32 i4_temporal_layer_id,
    224     WORD8 i1_cu_qp_delta_enabled_flag,
    225     void *pv_dep_mngr_encloop_dep_me);
    226 
    227 /*!
    228 ******************************************************************************
    229 * \if Function name : ihevce_me_process \endif
    230 *
    231 * \brief
    232 *    Frame level ME function
    233 *
    234 * \par Description:
    235 *    Processing of all layers starting from coarse and going
    236 *    to the refinement layers, all layers
    237 *    that are encoded go CTB by CTB. Outputs of this function are populated
    238 *    ctb_analyse_t structures, one per CTB.
    239 *
    240 * \param[in] pv_ctxt : pointer to ME module
    241 * \param[in] ps_enc_lap_inp  : pointer to input yuv buffer (frame buffer)
    242 * \param[in,out] ps_ctb_out : pointer to CTB analyse output structure (frame buffer)
    243 * \param[out] ps_cu_out : pointer to CU analyse output structure (frame buffer)
    244 * \param[in]  pd_intra_costs : pointerto intra cost buffer
    245 * \param[in]  ps_multi_thrd_ctxt : pointer to multi thread ctxt
    246 * \param[in]  thrd_id : Thread id of the current thrd in which function is executed
    247 *
    248 * \return
    249 *    None
    250 *
    251 * \author
    252 *  Ittiam
    253 *
    254 *****************************************************************************
    255 */
    256 void ihevce_me_process(
    257     void *pv_me_ctxt,
    258     ihevce_lap_enc_buf_t *ps_enc_lap_inp,
    259     ctb_analyse_t *ps_ctb_out,
    260     me_enc_rdopt_ctxt_t *ps_cur_out_me_prms,
    261     double *pd_intra_costs,
    262     ipe_l0_ctb_analyse_for_me_t *ps_ipe_analyse_ctb,
    263     pre_enc_L0_ipe_encloop_ctxt_t *ps_l0_ipe_input,
    264     void *pv_coarse_layer,
    265     multi_thrd_ctxt_t *ps_multi_thrd_ctxt,
    266     WORD32 i4_frame_parallelism_level,
    267     WORD32 thrd_id,
    268     WORD32 i4_me_frm_id);
    269 
    270 /*!
    271 ******************************************************************************
    272 * \if Function name : ihevce_me_frame_dpb_update \endif
    273 *
    274 * \brief
    275 *    Frame level ME initialisation function
    276 *
    277 * \par Description:
    278 *   Updation of ME's internal DPB
    279 *    based on available ref list information
    280 *
    281 * \param[in] pv_ctxt : pointer to ME module
    282 * \param[in] num_ref_l0 : Number of reference pics in L0 list
    283 * \param[in] num_ref_l1 : Number of reference pics in L1 list
    284 * \param[in] pps_rec_list_l0 : List of recon pics in L0 list
    285 * \param[in] pps_rec_list_l1 : List of recon pics in L1 list
    286 *
    287 * \return
    288 *    None
    289 *
    290 * \author
    291 *  Ittiam
    292 *
    293 *****************************************************************************
    294 */
    295 void ihevce_me_frame_dpb_update(
    296     void *pv_me_ctxt,
    297     WORD32 num_ref_l0,
    298     WORD32 num_ref_l1,
    299     recon_pic_buf_t **pps_rec_list_l0,
    300     recon_pic_buf_t **pps_rec_list_l1,
    301     WORD32 i4_thrd_id);
    302 
    303 void ihevce_derive_me_init_prms(
    304     ihevce_static_cfg_params_t *ps_init_prms,
    305     hme_init_prms_t *ps_hme_init_prms,
    306     S32 i4_num_proc_thrds,
    307     WORD32 i4_resolution_id);
    308 
    309 void ihevc_me_update_ref_desc(
    310     hme_ref_desc_t *ps_ref_desc,
    311     recon_pic_buf_t *ps_recon_pic,
    312     WORD32 ref_id_l0,
    313     WORD32 ref_id_l1,
    314     WORD32 ref_id_lc,
    315     WORD32 is_fwd);
    316 
    317 WORD32 ihevce_me_find_poc_in_list(
    318     recon_pic_buf_t **pps_rec_list, WORD32 poc, WORD32 i4_idr_gop_num, WORD32 num_ref);
    319 
    320 void ihevce_me_create_ref_map(
    321     recon_pic_buf_t **pps_rec_list_l0,
    322     recon_pic_buf_t **pps_rec_list_l1,
    323     WORD32 num_ref_l0_active,
    324     WORD32 num_ref_l1_active,
    325     WORD32 num_ref,
    326     hme_ref_map_t *ps_ref_map);
    327 
    328 /*!
    329 ******************************************************************************
    330 * \if Function name : ihevce_l0_me_frame_end \endif
    331 *
    332 * \brief
    333 *    End of frame update function performs
    334 *       - Dynamic Search Range collation
    335 *
    336 * \param[in] pv_ctxt : pointer to ME module
    337 *
    338 * \return
    339 *    None
    340 *
    341 * \author
    342 *  Ittiam
    343 *
    344 *****************************************************************************
    345 */
    346 void ihevce_l0_me_frame_end(
    347     void *pv_me_ctxt, WORD32 i4_idx_dvsr_p, WORD32 i4_display_num, WORD32 i4_me_frm_id);
    348 
    349 #endif /* _IHEVCE_ME_PASS_H_ */
    350