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 hme_err_compute.h
     23 *
     24 * \brief
     25 *    contains prototypes for functions that compute error or best results or
     26 *    return fxn ptrs for the same.
     27 *
     28 * \date
     29 *    18/09/2012
     30 *
     31 * \author
     32 *    Ittiam
     33 *
     34 ******************************************************************************
     35 */
     36 
     37 #ifndef _HME_ERR_COMPUTE_H_
     38 #define _HME_ERR_COMPUTE_H_
     39 
     40 /*****************************************************************************/
     41 /* Constant Macros                                                           */
     42 /*****************************************************************************/
     43 #define NUM_4X4 16
     44 #define NUM_4X4_IN_8x8 4
     45 #define NUM_4X4_IN_16x16 16
     46 #define NUM_8X8_IN_16x16 4
     47 #define NUM_8X8_IN_32x32 16
     48 #define NUM_8X8_IN_64x64 64
     49 #define NUM_16X16_IN_64x64 16
     50 #define NUM_ROWS_IN_4X4 4
     51 #define NUM_PIXELS_IN_ROW 4
     52 #define NUM_CANDIDATES_IN_GRID 9
     53 
     54 // 0 => best + good;
     55 // 1 => 1st and 2nd best;
     56 // good => worse or equal to second best
     57 #define BESTEST 0
     58 
     59 #define COST(a, b, c, d, e) (a)
     60 
     61 /*****************************************************************************/
     62 /* Functions                                                                 */
     63 /*****************************************************************************/
     64 void hme_evalsad_pt_npu_MxN_16bit(err_prms_t *ps_prms);
     65 
     66 #define compute_sad_16bit hme_evalsad_pt_npu_MxN_16bit
     67 
     68 /**
     69 ********************************************************************************
     70 *  @fn    S32 hme_update_results_grid_pu_bestn(result_upd_prms_t *ps_result_prms);
     71 *
     72 *  @brief  Updates the best N results based on a grid SAD for enabled partitions
     73 *
     74 *  @param[in,out]  ps_result_prms : contains parametrs pertaining to the results
     75 *
     76 *  @return None
     77 ********************************************************************************
     78 */
     79 void hme_update_results_grid_pu_bestn(result_upd_prms_t *ps_result_prms);
     80 
     81 void hme_update_results_grid_pu_bestn_xtreme_speed(result_upd_prms_t *ps_result_prms);
     82 
     83 /**
     84 ********************************************************************************
     85 *  @fn     hme_update_results_grid_pu_bestn_no_encode(result_upd_prms_t *ps_result_prms)
     86 *
     87 *  @brief  Updates results for the case where 1 best result is to be updated
     88 *          for a given pt, for several parts
     89 *          Note : The function is replicated for CLIPing the cost to 16bit to make
     90 *                  bit match with SIMD version
     91 *
     92 *  @param[in]  result_upd_prms_t : Contains the input parameters to this fxn
     93 *
     94 *  @return   The result_upd_prms_t structure is updated for all the active
     95 *            parts in case the current candt has results for any given part
     96 *             that is the best result for that part
     97 ********************************************************************************
     98 */
     99 void hme_update_results_grid_pu_bestn_no_encode(result_upd_prms_t *ps_result_prms);
    100 
    101 /**
    102 ********************************************************************************
    103 *  @fn     hme_get_result_fxn(i4_grid_mask, i4_part_mask, i4_num_results)
    104 *
    105 *  @brief  Implements predictive search with square grid refinement. In this
    106 *           case, the square grid is of step 1 always. since this is considered
    107 *           to be more of a refinement search
    108 *
    109 *  @param[in]  i4_grid_mask : Mask containing which of 9 grid pts active
    110 *
    111 *  @param[in]  i4_part_mask : Mask containing which of the 17 parts active
    112 *
    113 *  @param[in]  i4_num_results: Number of active results
    114 *
    115 *  @return   Pointer to the appropriate result update function
    116 *             (type PF_RESULT_FXN_T)
    117 ********************************************************************************
    118 */
    119 PF_RESULT_FXN_T hme_get_result_fxn(S32 i4_grid_mask, S32 i4_part_mask, S32 i4_num_results);
    120 
    121 void compute_satd_16bit(err_prms_t *ps_prms);
    122 
    123 void compute_satd_8bit(err_prms_t *ps_prms);
    124 
    125 void compute_sad_16bit(err_prms_t *ps_prms);
    126 
    127 S32 compute_mv_cost(search_node_t *ps_search_node, pred_ctxt_t *ps_pred_ctxt, BLK_SIZE_T e_blk_size);
    128 
    129 void hme_init_pred_ctxt_no_encode(
    130     pred_ctxt_t *ps_pred_ctxt,
    131     search_results_t *ps_search_results,
    132     search_node_t *ps_top_candts,
    133     search_node_t *ps_left_candts,
    134     search_node_t **pps_proj_coloc_candts,
    135     search_node_t *ps_coloc_candts,
    136     search_node_t *ps_zeromv_candt,
    137     S32 pred_lx,
    138     S32 lambda,
    139     S32 lambda_q_shift,
    140     U08 **ppu1_ref_bits_tlu,
    141     S16 *pi2_ref_scf);
    142 
    143 void hme_init_pred_ctxt_encode(
    144     pred_ctxt_t *ps_pred_ctxt,
    145     search_results_t *ps_search_results,
    146     search_node_t *ps_coloc_candts,
    147     search_node_t *ps_zeromv_candt,
    148     mv_grid_t *ps_mv_grid,
    149     S32 pred_lx,
    150     S32 lambda,
    151     S32 lambda_q_shift,
    152     U08 **ppu1_ref_bits_tlu,
    153     S16 *pi2_ref_scf);
    154 
    155 /**
    156 ********************************************************************************
    157 *  @fn     compute_mv_cost_coarse(search_node_t *ps_node,
    158 *                   pred_ctxt_t *ps_pred_ctxt,
    159 *                   PART_ID_T e_part_id)
    160 *
    161 *  @brief  MV cost for coarse explicit search in coarsest layer
    162 *
    163 *  @param[in]  ps_node: search node having mv and ref id for which to eval cost
    164 *
    165 *  @param[in]  ps_pred_ctxt : mv pred context
    166 *
    167 *  @param[in]  e_part_id : Partition id.
    168 *
    169 *  @return   Cost value
    170 
    171 ********************************************************************************
    172 */
    173 S32 compute_mv_cost_coarse(
    174     search_node_t *ps_node, pred_ctxt_t *ps_pred_ctxt, PART_ID_T e_part_id, S32 inp_mv_pel);
    175 
    176 /**
    177 ********************************************************************************
    178 *  @fn     compute_mv_cost_coarse(search_node_t *ps_node,
    179 *                   pred_ctxt_t *ps_pred_ctxt,
    180 *                   PART_ID_T e_part_id)
    181 *
    182 *  @brief  MV cost for coarse explicit search in coarsest layer
    183 *
    184 *  @param[in]  ps_node: search node having mv and ref id for which to eval cost
    185 *
    186 *  @param[in]  ps_pred_ctxt : mv pred context
    187 *
    188 *  @param[in]  e_part_id : Partition id.
    189 *
    190 *  @return   Cost value
    191 
    192 ********************************************************************************
    193 */
    194 S32 compute_mv_cost_coarse_high_speed(
    195     search_node_t *ps_node, pred_ctxt_t *ps_pred_ctxt, PART_ID_T e_part_id, S32 inp_mv_pel);
    196 
    197 /**
    198 ********************************************************************************
    199 *  @fn     compute_mv_cost_coarse(search_node_t *ps_node,
    200 *                   pred_ctxt_t *ps_pred_ctxt,
    201 *                   PART_ID_T e_part_id)
    202 *
    203 *  @brief  MV cost for coarse explicit search in coarsest layer
    204 *
    205 *  @param[in]  ps_node: search node having mv and ref id for which to eval cost
    206 *
    207 *  @param[in]  ps_pred_ctxt : mv pred context
    208 *
    209 *  @param[in]  e_part_id : Partition id.
    210 *
    211 *  @return   Cost value
    212 
    213 ********************************************************************************
    214 */
    215 S32 compute_mv_cost_refine(
    216     search_node_t *ps_node, pred_ctxt_t *ps_pred_ctxt, PART_ID_T e_part_id, S32 inp_mv_pel);
    217 
    218 /**
    219 ********************************************************************************
    220 *  @fn     compute_mv_cost_explicit(search_node_t *ps_node,
    221 *                   pred_ctxt_t *ps_pred_ctxt,
    222 *                   PART_ID_T e_part_id)
    223 *
    224 *  @brief  MV cost for explicit search in layers not encoded
    225 *
    226 *  @param[in]  ps_node: search node having mv and ref id for which to eval cost
    227 *
    228 *  @param[in]  ps_pred_ctxt : mv pred context
    229 *
    230 *  @param[in]  e_part_id : Partition id.
    231 *
    232 *  @return   Cost value
    233 
    234 ********************************************************************************
    235 */
    236 S32 compute_mv_cost_explicit(
    237     search_node_t *ps_node, pred_ctxt_t *ps_pred_ctxt, PART_ID_T e_part_id, S32 inp_mv_pel);
    238 
    239 S32 compute_mv_cost_implicit(
    240     search_node_t *ps_node, pred_ctxt_t *ps_pred_ctxt, PART_ID_T e_part_id, S32 inp_mv_pel);
    241 
    242 S32 compute_mv_cost_implicit_high_speed(
    243     search_node_t *ps_node, pred_ctxt_t *ps_pred_ctxt, PART_ID_T e_part_id, S32 inp_mv_pel);
    244 
    245 S32 compute_mv_cost_implicit_high_speed_modified(
    246     search_node_t *ps_node, pred_ctxt_t *ps_pred_ctxt, PART_ID_T e_part_id, S32 inp_mv_pel);
    247 
    248 void hme_evalsad_grid_pu_16x16(err_prms_t *ps_prms);
    249 
    250 void hme_evalsatd_pt_pu_8x8(err_prms_t *ps_prms);
    251 
    252 WORD32 hme_evalsatd_pt_pu_8x8_tu_rec(
    253     err_prms_t *ps_prms,
    254     WORD32 lambda,
    255     WORD32 lambda_q_shift,
    256     WORD32 i4_frm_qstep,
    257     me_func_selector_t *ps_func_selector);
    258 
    259 void hme_evalsatd_update_1_best_result_pt_pu_16x16(
    260     err_prms_t *ps_prms, result_upd_prms_t *ps_result_prms);
    261 
    262 WORD32 hme_evalsatd_pt_pu_32x32_tu_rec(
    263     err_prms_t *ps_prms,
    264     WORD32 lambda,
    265     WORD32 lambda_q_shift,
    266     WORD32 i4_frm_qstep,
    267     me_func_selector_t *ps_func_selector);
    268 
    269 void hme_evalsatd_pt_pu_32x32(err_prms_t *ps_prms);
    270 
    271 void hme_evalsatd_pt_pu_64x64(err_prms_t *ps_prms);
    272 
    273 WORD32 hme_evalsatd_pt_pu_64x64_tu_rec(
    274     err_prms_t *ps_prms,
    275     WORD32 lambda,
    276     WORD32 lambda_q_shift,
    277     WORD32 i4_frm_qstep,
    278     me_func_selector_t *ps_func_selector);
    279 
    280 WORD32 hme_evalsatd_pt_pu_16x16_tu_rec(
    281     err_prms_t *ps_prms,
    282     WORD32 lambda,
    283     WORD32 lambda_q_shift,
    284     WORD32 i4_frm_qstep,
    285     me_func_selector_t *ps_func_selector);
    286 
    287 void ihevce_had_32x32_r(
    288     UWORD8 *pu1_src,
    289     WORD32 src_strd,
    290     UWORD8 *pu1_pred,
    291     WORD32 pred_strd,
    292     WORD16 *pi2_dst,
    293     WORD32 dst_strd,
    294     WORD32 **ppi4_hsad,
    295     WORD32 **ppi4_tu_split,
    296     WORD32 **ppi4_tu_early_cbf,
    297     WORD32 pos_x_y_4x4,
    298     WORD32 num_4x4_in_row,
    299     WORD32 lambda,
    300     WORD32 lambda_q_shift,
    301     WORD32 i4_frm_qstep,
    302     WORD32 i4_cur_depth,
    303     WORD32 i4_max_depth,
    304     WORD32 i4_max_tr_size,
    305     WORD32 *pi4_tu_split_cost,
    306     me_func_selector_t *ps_func_selector);
    307 
    308 void hme_update_results_pt_pu_best1_subpel_hs(
    309     err_prms_t *ps_err_prms, result_upd_prms_t *ps_result_prms);
    310 
    311 void hme_set_mvp_node(
    312     search_results_t *ps_search_results,
    313     search_node_t *ps_candt_prj_coloc,
    314     U08 u1_pred_lx,
    315     U08 u1_default_ref_id);
    316 
    317 S32 hme_cmp_nodes(search_node_t *ps_best_node1, search_node_t *ps_best_node2);
    318 
    319 #endif /* #ifndef _HME_SEARCH_ALGO_H_*/
    320