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_coarse_me_pass.h
     23 *
     24 * \brief
     25 *    Interfaces to create, control and run the Coarse ME module
     26 *
     27 * \date
     28 *    22/10/2012
     29 *
     30 * \author
     31 *    Ittiam
     32 *
     33 ******************************************************************************
     34 */
     35 
     36 #ifndef _IHEVCE_COARSE_ME_PASS_H_
     37 #define _IHEVCE_COARSE_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 ******************************************************************************
     69 * \if Function name : ihevce_me_get_num_mem_recs \endif
     70 *
     71 * \brief
     72 *    Number of memory records are returned for ME module
     73 *
     74 *
     75 * \return
     76 *    Number of memory records
     77 *
     78 * \author
     79 *  Ittiam
     80 *
     81 *****************************************************************************
     82 */
     83 WORD32 ihevce_coarse_me_get_num_mem_recs();
     84 
     85 /*!
     86 ******************************************************************************
     87 * \if Function name : ihevce_coarse_me_get_mem_recs \endif
     88 *
     89 * \brief
     90 *    Memory requirements are returned for coarse ME.
     91 *
     92 * \param[in,out]  ps_mem_tab : pointer to memory descriptors table
     93 * \param[in] ps_init_prms : Create time static parameters
     94 * \param[in] i4_num_proc_thrds : Number of processing threads for this module
     95 * \param[in] i4_mem_space : memspace in whihc memory request should be done
     96 *
     97 * \return
     98 *    Number of records
     99 *
    100 * \author
    101 *  Ittiam
    102 *
    103 *****************************************************************************
    104 */
    105 WORD32 ihevce_coarse_me_get_mem_recs(
    106     iv_mem_rec_t *ps_mem_tab,
    107     ihevce_static_cfg_params_t *ps_init_prms,
    108     WORD32 i4_num_proc_thrds,
    109     WORD32 i4_mem_space,
    110     WORD32 i4_resolution_id);
    111 
    112 /*!
    113 ******************************************************************************
    114 * \if Function name : ihevce_coarse_me_init \endif
    115 *
    116 * \brief
    117 *    Intialization for ME context state structure .
    118 *
    119 * \param[in] ps_mem_tab : pointer to memory descriptors table
    120 * \param[in] ps_init_prms : Create time static parameters
    121 * \param[in] pv_osal_handle : Osal handle
    122 *
    123 * \return
    124 *    Handle to the ME context
    125 *
    126 * \author
    127 *  Ittiam
    128 *
    129 *****************************************************************************
    130 */
    131 void *ihevce_coarse_me_init(
    132     iv_mem_rec_t *ps_mem_tab,
    133     ihevce_static_cfg_params_t *ps_init_prms,
    134     WORD32 i4_num_proc_thrds,
    135     void *pv_osal_handle,
    136     WORD32 i4_resolution_id,
    137     UWORD8 u1_is_popcnt_available);
    138 
    139 /*!
    140 ******************************************************************************
    141 * \if Function name : ihevce_coarse_me_reg_thrds_sem \endif
    142 *
    143 * \brief
    144 *    Intialization for ME context state structure with semaphores .
    145 *
    146 * \param[in] pv_me_ctxt : pointer to Coarse ME ctxt
    147 * \param[in] ppv_sem_hdls : Arry of semaphore handles
    148 * \param[in] i4_num_proc_thrds : Number of processing threads
    149 *
    150 * \return
    151 *   none
    152 *
    153 * \author
    154 *  Ittiam
    155 *
    156 *****************************************************************************
    157 */
    158 void ihevce_coarse_me_reg_thrds_sem(void *pv_me_ctxt, void **ppv_sem_hdls, WORD32 i4_num_proc_thrds);
    159 
    160 /*!
    161 ******************************************************************************
    162 * \if Function name : ihevce_coarse_me_delete \endif
    163 *
    164 * \brief
    165 *    Destroy Coarse ME module
    166 * Note : Only Destroys the resources allocated in the module like
    167 *   semaphore,etc. Memory free is done Separately using memtabs
    168 *
    169 * \param[in] pv_me_ctxt : pointer to Coarse ME ctxt
    170 * \param[in] ps_init_prms : Create time static parameters
    171 *
    172 * \return
    173 *    None
    174 *
    175 * \author
    176 *  Ittiam
    177 *
    178 *****************************************************************************
    179 */
    180 void ihevce_coarse_me_delete(
    181     void *pv_me_ctxt, ihevce_static_cfg_params_t *ps_init_prms, WORD32 i4_resolution_id);
    182 
    183 /**
    184 *******************************************************************************
    185 * \if Function name : ihevce_me_set_resolution \endif
    186 *
    187 * \brief
    188 *    Sets the resolution for ME state
    189 *
    190 * \par Description:
    191 *    ME requires information of resolution to prime up its layer descriptors
    192 *    and contexts. This API is called whenever a control call from application
    193 *    causes a change of resolution. Has to be called once initially before
    194 *    processing any frame. Again this is just a glue function and calls the
    195 *    actual ME API for the same.
    196 *
    197 * \param[in,out] pv_me_ctxt: Handle to the ME context
    198 * \param[in] n_enc_layers: Number of layers getting encoded
    199 * \param[in] p_wd : Pointer containing widths of each layer getting encoded.
    200 * \param[in] p_ht : Pointer containing heights of each layer getting encoded.
    201 *
    202 * \returns
    203 *  none
    204 *
    205 * \author
    206 *  Ittiam
    207 *
    208 *******************************************************************************
    209 */
    210 void ihevce_coarse_me_set_resolution(
    211     void *pv_me_ctxt, WORD32 n_enc_layers, WORD32 *p_wd, WORD32 *p_ht);
    212 
    213 void ihevce_coarse_me_get_rc_param(
    214     void *pv_me_ctxt,
    215     LWORD64 *i8_acc_frame_hme_cost,
    216     LWORD64 *i8_acc_frame_hme_sad,
    217     LWORD64 *i8_acc_num_blks_higher_sad,
    218     LWORD64 *i8_total_blks,
    219     WORD32 i4_is_prev_pic_same_scene);
    220 /*!
    221 ******************************************************************************
    222 * \if Function name : ihevce_me_frame_init \endif
    223 *
    224 * \brief
    225 *    Frame level ME initialisation function
    226 *
    227 * \par Description:
    228 *    The following pre-conditions exist for this function: a. We have the input
    229 *    pic ready for encode, b. We have the reference list with POC, L0/L1 IDs
    230 *    and ref ptrs ready for this picture and c. ihevce_me_set_resolution has
    231 *    been called atleast once. Once these are supplied, the following are
    232 *    done here: a. Input pyramid creation, b. Updation of ME's internal DPB
    233 *    based on available ref list information
    234 *
    235 * \param[in] pv_ctxt : pointer to ME module
    236 * \param[in] ps_frm_ctb_prms : CTB characteristics parameters
    237 * \param[in] ps_frm_lamda : Frame level Lambda params
    238 * \param[in] num_ref_l0 : Number of reference pics in L0 list
    239 * \param[in] num_ref_l1 : Number of reference pics in L1 list
    240 * \param[in] num_ref_l0_active : Active reference pics in L0 dir for current frame (shall be <= num_ref_l0)
    241 * \param[in] num_ref_l1_active : Active reference pics in L1 dir for current frame (shall be <= num_ref_l1)
    242 * \param[in] pps_rec_list_l0 : List of recon pics in L0 list
    243 * \param[in] pps_rec_list_l1 : List of recon pics in L1 list
    244 * \param[in] ps_enc_lap_inp  : pointer to input yuv buffer (frame buffer)
    245 * \param[in] i4_frm_qp       : current picture QP
    246 *
    247 * \return
    248 *    None
    249 *
    250 * \author
    251 *  Ittiam
    252 *
    253 *****************************************************************************
    254 */
    255 void ihevce_coarse_me_frame_init(
    256     void *pv_me_ctxt,
    257     ihevce_static_cfg_params_t *ps_stat_prms,
    258     frm_ctb_ctxt_t *ps_frm_ctb_prms,
    259     frm_lambda_ctxt_t *ps_frm_lamda,
    260     WORD32 num_ref_l0,
    261     WORD32 num_ref_l1,
    262     WORD32 num_ref_l0_active,
    263     WORD32 num_ref_l1_active,
    264     recon_pic_buf_t **pps_rec_list_l0,
    265     recon_pic_buf_t **pps_rec_list_l1,
    266     ihevce_lap_enc_buf_t *ps_enc_lap_inp,
    267     WORD32 i4_frm_qp,
    268     ihevce_ed_blk_t *ps_layer1_buf,  //EIID
    269     ihevce_ed_ctb_l1_t *ps_ed_ctb_l1,
    270     UWORD8 *pu1_me_reverse_map_info,
    271     WORD32 i4_temporal_layer_id);
    272 
    273 /*!
    274 ******************************************************************************
    275 * \if Function name : ihevce_me_process \endif
    276 *
    277 * \brief
    278 *    Frame level ME function
    279 *
    280 * \par Description:
    281 *    Processing of all layers starting from coarse and going
    282 *    to the refinement layers, all layers
    283 *    that are encoded go CTB by CTB. Outputs of this function are populated
    284 *    ctb_analyse_t structures, one per CTB.
    285 *
    286 * \param[in] pv_ctxt : pointer to ME module
    287 * \param[in] ps_enc_lap_inp  : pointer to input yuv buffer (frame buffer)
    288 * \param[in,out] ps_ctb_out : pointer to CTB analyse output structure (frame buffer)
    289 * \param[out] ps_cu_out : pointer to CU analyse output structure (frame buffer)
    290 * \param[in]  pd_intra_costs : pointerto intra cost buffer
    291 * \param[in]  ps_multi_thrd_ctxt : pointer to multi thread ctxt
    292 * \param[in]  thrd_id : Thread id of the current thrd in which function is executed
    293 *
    294 * \return
    295 *    None
    296 *
    297 * \author
    298 *  Ittiam
    299 *
    300 *****************************************************************************
    301 */
    302 void ihevce_coarse_me_process(
    303     void *pv_me_ctxt,
    304     ihevce_lap_enc_buf_t *ps_enc_lap_inp,
    305     multi_thrd_ctxt_t *ps_multi_thrd_ctxt,
    306     WORD32 thrd_id,
    307     WORD32 i4_ping_pong);
    308 
    309 /*!
    310 ******************************************************************************
    311 * \if Function name : ihevce_me_frame_dpb_update \endif
    312 *
    313 * \brief
    314 *    Frame level ME initialisation function
    315 *
    316 * \par Description:
    317 *   Updation of ME's internal DPB
    318 *    based on available ref list information
    319 *
    320 * \param[in] pv_ctxt : pointer to ME module
    321 * \param[in] num_ref_l0 : Number of reference pics in L0 list
    322 * \param[in] num_ref_l1 : Number of reference pics in L1 list
    323 * \param[in] pps_rec_list_l0 : List of recon pics in L0 list
    324 * \param[in] pps_rec_list_l1 : List of recon pics in L1 list
    325 *
    326 * \return
    327 *    None
    328 *
    329 * \author
    330 *  Ittiam
    331 *
    332 *****************************************************************************
    333 */
    334 void ihevce_coarse_me_frame_dpb_update(
    335     void *pv_me_ctxt,
    336     WORD32 num_ref_l0,
    337     WORD32 num_ref_l1,
    338     recon_pic_buf_t **pps_rec_list_l0,
    339     recon_pic_buf_t **pps_rec_list_l1);
    340 
    341 /*!
    342 ******************************************************************************
    343 * \if Function name : ihevce_me_get_lyr_prms_job_que \endif
    344 *
    345 * \brief Returns to the caller key attributes related to dependency between layers
    346 *          for multi-thread execution
    347 *
    348 *
    349 * \par Description:
    350 *    This function requires the precondition that the width and ht of encode
    351 *    layer is known, and ME API ihevce_me_set_resolution() API called with
    352 *    this info. Based on this, ME populates useful information for the encoder
    353 *    to execute the multi-thread (concurrent across layers) in this API.
    354 *    The number of layers, number of vertical units in each layer, and for
    355 *    each vertial unit in each layer, its dependency on previous layer's units
    356 *    From ME's perspective, a vertical unit is one which is smallest min size
    357 *    vertically (and spans the entire row horizontally). This is CTB for encode
    358 *    layer, and 8x8 / 4x4 for non encode layers.
    359 *
    360 * \param[in] pv_ctxt : ME handle
    361 * \param[in] ps_curr_inp : Input buffer descriptor
    362 * \param[out] pi4_num_hme_lyrs : Num of HME layers (ME updates)
    363 * \param[out] pi4_num_vert_units_in_lyr : Array of size N (num layers), each
    364 *                     entry has num vertical units in that particular layer
    365 * \param[in] ps_me_job_q_prms : Array of job queue prms, one for each unit in a
    366 *                 layer. Note that this is contiguous in order of processing
    367 *                 All k units of layer N-1 from top to bottom, followed by
    368 *                 all m units of layer N-2 .... ends with X units of layer 0
    369 *
    370 * \return
    371 *    None
    372 *
    373 * \author
    374 *  Ittiam
    375 *
    376 *****************************************************************************
    377 */
    378 void ihevce_coarse_me_get_lyr_prms_job_que(
    379     void *pv_me_ctxt,
    380     ihevce_lap_enc_buf_t *ps_curr_inp,
    381     WORD32 *pi4_num_hme_lyrs,
    382     WORD32 *pi4_num_vert_units_in_lyr,
    383     multi_thrd_me_job_q_prms_t *ps_me_job_q_prms);
    384 
    385 /*!
    386 ******************************************************************************
    387 * \if Function name : ihevce_me_frame_end \endif
    388 *
    389 * \brief
    390 *    End of frame update function performs GMV collation
    391 *
    392 * \param[in] pv_ctxt : pointer to ME module
    393 *
    394 * \return
    395 *    None
    396 *
    397 * \author
    398 *  Ittiam
    399 *
    400 *****************************************************************************
    401 */
    402 void ihevce_coarse_me_frame_end(void *pv_me_ctxt);
    403 
    404 void ihevce_coarse_me_get_lyr1_ctxt(
    405     void *pv_me_ctxt, void *pv_layer_ctxt, void *pv_layer_mv_bank_ctxt);
    406 
    407 void ihevce_coarse_me_set_lyr1_mv_bank(
    408     void *pv_me_ctxt,
    409     ihevce_lap_enc_buf_t *ps_enc_lap_inp,
    410     void *pv_mv_bank,
    411     void *pv_ref_idx_bank,
    412     WORD32 i4_curr_idx);
    413 
    414 WORD32 ihevce_coarse_me_get_lyr_buf_desc(
    415     void *pv_me_ctxt, UWORD8 **ppu1_decomp_lyr_bufs, WORD32 *pi4_lyr_buf_stride);
    416 
    417 #endif /* _IHEVCE_COARSE_ME_PASS_H_ */
    418